7.0.0 • Published 5 months ago

@octokit/request-error v7.0.0

Weekly downloads
4,665,581
License
MIT
Repository
github
Last release
5 months ago

request-error.js

Error class for Octokit request errors

@latest Build Status

Usage

Install with npm install @octokit/request-error

import { RequestError } from "@octokit/request-error";

!IMPORTANT As we use conditional exports, you will need to adapt your tsconfig.json by setting "moduleResolution": "node16", "module": "node16".

See the TypeScript docs on package.json "exports". See this helpful guide on transitioning to ESM from @sindresorhus

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

@octokit/request@octokit/core@everything-registry/sub-chunk-676testing-bugsyjshawl-octokit-rest-no-at-signkeptn-provisioning@wearerequired/generate@wordpress/project-management-automation@tg44/octokit-webhooks.js@trigger.dev/github@zendeskgarden/scripts@hackney/mtfh-cli@actions/artifact@actions/github@haruyukilxz/tools@cpdevtools/development-host@copilot-extensions/preview-sdkgh-org-scan@infinitebrahmanuniverse/nolb-_oc@kie/build-chain-action@pz-mxu/release-please@probot-ng/core@owlgrid-dev/owl-access@owlgrid-dev/owl-workspace@rnx-kit/buildmobbdevoryx-crm-api-requestoctokitrelease-please-forkrelease-pleaserelease-please-plusrelease-please_bukforksfroment-release-pleasesock-secretgitroverftl-release-pleasegardener-installation@spotify/backstage-plugin-soundcheck-backend-module-github@systemfsoftware/trigger.dev_github@takeshape/shape-toolsfetch-github-folder@jlvandenhout/docusaurus-plugin-docs-editor@lucarickli/jamstack-cms@lui-design/coverage-report@electron-forge/publisher-github@docupotamus/docusaurus-theme-editor@joaquinjsb/release-please@npmcli/release-please@dogu-tech/node@opencollective/auth-simple-oauth-app@ones-design/coverage-report@octokit/webhooks@octokit/auth-app@octokit/auth-basic@octokit/plugin-retry@octokit/oauth-methods@octokit/plugin-create-or-update-text-file@octokit/plugin-enterprise-compatibility@octokit/auth-unauthenticated@jupiterone/graph-github@justforlxz/tools@garden-io/grow-plugin-github@octorelease/github@dotcom-tool-kit/heroku@github/dependency-submission-toolkit@mgga/auth-app
5.1.1

8 months ago

7.0.0

5 months ago

6.1.6

10 months ago

6.1.8

6 months ago

6.1.7

8 months ago

6.1.5

1 year ago

6.1.2

1 year ago

6.1.4

1 year ago

6.1.3

1 year ago

6.1.1

2 years ago

5.1.0

2 years ago

6.1.0

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.0-beta.3

2 years ago

6.0.0-beta.4

2 years ago

6.0.0-beta.5

2 years ago

6.0.0-beta.1

2 years ago

6.0.0-beta.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.2

2 years ago

3.0.3

3 years ago

3.0.2

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.0.6

4 years ago

2.1.0

4 years ago

2.0.5

5 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

6 years ago

1.2.1

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago