A package that provides human-readable descriptions and helper methods for HTTP status codes.
$ npm install --save statusmate-http
or you can use yarn
$ yarn add statusmate-http
Import statusmate-http into your app
import {
getStatusDescription,
isServerError,
isClientError,
isSuccess,
isRedirection,
isInformational,
} from 'statusmate-http';
You can retrieve the human-readable description of an HTTP status code using getStatusDescription
:
const description = getStatusDescription(404); //Not Found
console.log(description);
You can check if a status code indicates a server error using isServerError
:
const isError = isServerError(500); // true
console.log(isError);
Similarly, you can check if a status code is a client error using isClientError
:
const isError = isClientError(404); // true
console.log(isError);
To check if a status code indicates a successful response:
const isOk = isSuccess(200); // true
console.log(isOk);
To check if a status code indicates a redirection:
const isRedirect = isRedirection(302); // true
console.log(isRedirect);
You can check if a status code is informational:
const isInfo = isInformational(100); // true
console.log(isInfo);
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D