6.1.1 • Published 10 days ago

@octokit/request-error v6.1.1

Weekly downloads
4,665,581
License
MIT
Repository
github
Last release
10 days ago

http-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

6.1.1

10 days ago

5.1.0

21 days ago

6.1.0

23 days ago

6.0.3

23 days ago

6.0.2

2 months ago

6.0.1

2 months ago

6.0.0

2 months ago

6.0.0-beta.3

2 months ago

6.0.0-beta.4

2 months ago

6.0.0-beta.5

2 months ago

6.0.0-beta.1

2 months ago

6.0.0-beta.2

2 months ago

5.0.1

7 months ago

5.0.0

10 months ago

4.0.1

11 months ago

4.0.0

11 months ago

4.0.2

10 months ago

3.0.3

1 year ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.0.6

3 years ago

2.1.0

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago