tree: f35a038a5e75da778d1f9d37e6d479a5506d4fa8 [path history] [tgz]
  1. dist-node/
  2. dist-src/
  3. dist-types/
  4. dist-web/
  5. LICENSE
  6. package.json
  7. README.md
actions/bcr-pr-review-notifier/node_modules/@octokit/request-error/README.md

http-error.js

Error class for Octokit request errors

@latest Build Status

Usage

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

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