1 | # http-error.js
|
2 |
|
3 | > Error class for Octokit request errors
|
4 |
|
5 | [![@latest](https://img.shields.io/npm/v/@octokit/request-error.svg)](https://www.npmjs.com/package/@octokit/request-error)
|
6 | [![Build Status](https://github.com/octokit/request-error.js/workflows/Test/badge.svg)](https://github.com/octokit/request-error.js/actions?query=workflow%3ATest)
|
7 |
|
8 | ## Usage
|
9 |
|
10 | <table>
|
11 | <tbody valign=top align=left>
|
12 | <tr><th>
|
13 | Browsers
|
14 | </th><td width=100%>
|
15 | Load <code>@octokit/request-error</code> directly from <a href="https://cdn.skypack.dev">cdn.skypack.dev</a>
|
16 |
|
17 | ```html
|
18 | <script type="module">
|
19 | import { RequestError } from "https://cdn.skypack.dev/@octokit/request-error";
|
20 | </script>
|
21 | ```
|
22 |
|
23 | </td></tr>
|
24 | <tr><th>
|
25 | Node
|
26 | </th><td>
|
27 |
|
28 | Install with <code>npm install @octokit/request-error</code>
|
29 |
|
30 | ```js
|
31 | const { RequestError } = require("@octokit/request-error");
|
32 | // or: import { RequestError } from "@octokit/request-error";
|
33 | ```
|
34 |
|
35 | </td></tr>
|
36 | </tbody>
|
37 | </table>
|
38 |
|
39 | ```js
|
40 | const error = new RequestError("Oops", 500, {
|
41 | headers: {
|
42 | "x-github-request-id": "1:2:3:4",
|
43 | }, // response headers
|
44 | request: {
|
45 | method: "POST",
|
46 | url: "https://api.github.com/foo",
|
47 | body: {
|
48 | bar: "baz",
|
49 | },
|
50 | headers: {
|
51 | authorization: "token secret123",
|
52 | },
|
53 | },
|
54 | });
|
55 |
|
56 | error.message; // Oops
|
57 | error.status; // 500
|
58 | error.request.method; // POST
|
59 | error.request.url; // https://api.github.com/foo
|
60 | error.request.body; // { bar: 'baz' }
|
61 | error.request.headers; // { authorization: 'token [REDACTED]' }
|
62 | error.response; // { url, status, headers, data }
|
63 | ```
|
64 |
|
65 | ## LICENSE
|
66 |
|
67 | [MIT](LICENSE)
|