change-string-case/node_modules/@octokit/request-error
Alex Szczuczko d0603cd0a7 npm install
2023-10-25 14:27:07 -06:00
..
dist-node npm install 2023-10-25 14:27:07 -06:00
dist-src npm install 2023-10-25 14:27:07 -06:00
dist-types npm install 2023-10-25 14:27:07 -06:00
dist-web npm install 2023-10-25 14:27:07 -06:00
LICENSE Add back in node_modules, updated 2022-11-03 10:55:07 -06:00
package.json npm install 2023-10-25 14:27:07 -06:00
README.md npm install 2023-10-25 14:27:07 -06:00

http-error.js

Error class for Octokit request errors

@latest Build Status

Usage

Browsers Load @octokit/request-error directly from esm.sh
<script type="module">
import { RequestError } from "https://esm.sh/@octokit/request-error";
</script>
Node

Install with npm install @octokit/request-error

const { RequestError } = require("@octokit/request-error");
// or: import { RequestError } from "@octokit/request-error";
const error = new RequestError("Oops", 500, {
  request: {
    method: "POST",
    url: "https://api.github.com/foo",
    body: {
      bar: "baz",
    },
    headers: {
      authorization: "token secret123",
    },
  },
  response: {
    status: 500,
    url: "https://api.github.com/foo",
    headers: {
      "x-github-request-id": "1:2:3:4",
    },
    data: {
      foo: "bar",
    },
  },
});

error.message; // Oops
error.status; // 500
error.request; // { method, url, headers, body }
error.response; // { url, status, headers, data }

Usage with Octokit

try {
  // your code here that sends at least one Octokit request
  await octokit.request("GET /");
} catch (error) {
  // Octokit errors always have a `error.status` property which is the http response code
  if (error.status) {
    // handle Octokit error
  } else {
    // handle all other errors
    throw error;
  }
}

LICENSE

MIT