wishthis/node_modules/@octokit/request-error/README.md

72 lines
1.5 KiB
Markdown
Raw Normal View History

2022-01-21 08:28:41 +00:00
# http-error.js
> Error class for Octokit request errors
[![@latest](https://img.shields.io/npm/v/@octokit/request-error.svg)](https://www.npmjs.com/package/@octokit/request-error)
2022-06-08 10:36:39 +00:00
[![Build Status](https://github.com/octokit/request-error.js/workflows/Test/badge.svg)](https://github.com/octokit/request-error.js/actions?query=workflow%3ATest)
2022-01-21 08:28:41 +00:00
## Usage
<table>
<tbody valign=top align=left>
<tr><th>
Browsers
</th><td width=100%>
2022-06-08 10:36:39 +00:00
Load <code>@octokit/request-error</code> directly from <a href="https://cdn.skypack.dev">cdn.skypack.dev</a>
2022-01-21 08:28:41 +00:00
```html
<script type="module">
2022-06-08 10:36:39 +00:00
import { RequestError } from "https://cdn.skypack.dev/@octokit/request-error";
2022-01-21 08:28:41 +00:00
</script>
```
</td></tr>
<tr><th>
Node
</th><td>
Install with <code>npm install @octokit/request-error</code>
```js
const { RequestError } = require("@octokit/request-error");
// or: import { RequestError } from "@octokit/request-error";
```
</td></tr>
</tbody>
</table>
```js
const error = new RequestError("Oops", 500, {
request: {
method: "POST",
url: "https://api.github.com/foo",
body: {
2022-06-08 10:36:39 +00:00
bar: "baz",
2022-01-21 08:28:41 +00:00
},
headers: {
2022-06-08 10:36:39 +00:00
authorization: "token secret123",
},
},
2022-07-11 11:25:19 +00:00
response: {
status: 500,
url: "https://api.github.com/foo"
headers: {
"x-github-request-id": "1:2:3:4",
},
data: {
foo: "bar"
}
},
2022-01-21 08:28:41 +00:00
});
error.message; // Oops
error.status; // 500
2022-07-11 11:25:19 +00:00
error.request; // { method, url, headers, body }
2022-06-08 10:36:39 +00:00
error.response; // { url, status, headers, data }
2022-01-21 08:28:41 +00:00
```
## LICENSE
[MIT](LICENSE)