프로젝트
GitHub에서 보기
kbariotis/throw.js
소개
다음 REST API에서 사용할 수 있는 HTTP 오류 모음
기타 프로젝트측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Originalthrow.js
An HTTP Error collection to use in your next REST API.
Installation
npm install --save throw.js
or
yarn add throw.js
Example
const express = require("express");
const app = express();
const { NotFound } = require("throw.js");
const logger = require("winston");
app.get("/", (req, res, next) => {
next(new NotFound());
});
app.use((err, req, res, next) => {
logger.error(err);
if (req.app.get("env") !== "development" && req.app.get("env") !== "test") {
delete err.stack;
}
res.status(err.statusCode || 500).json(err);
});
app.listen(3000);
Custom Errors
const { CustomError } = require("throw.js");
throw new CustomError(message, statusCode?, errorCode?, originalError?);
Parameters:
- message[optional]: Detailed message of this error
- statusCode[optional]: The HTTP Status number to return
- errorCode[optional]: An internal unique code identifier of this error
Stacking Errors
const { CustomError } = require("throw.js");
try {
// throws an error
} catch (e) {
// Pass the error as a parameter to keep its original stack trace
throw new CustomError(message, statusCode, errorCode, e);
}
Errors
All of the classes below have all parameters set up by default, based on RFC7231.
But you can override the message and the errorCode to fit your for personal needs.
400 Bad Request
BadRequest(message?, errorCode?, originalError?);
401 Unauthorized
Unauthorized(message?, errorCode?, originalError?);
402 Payment Required
PaymentRequired(message?, errorCode?, originalError?);
403 Forbidden
Forbidden(message?, errorCode?, originalError?);
404 Not Found
NotFound(message?, errorCode?, originalError?);
405 Method Not Allowed
MethodNotAllowed(message?, errorCode?, originalError?);
406 Not Acceptable
NotAcceptable(message?, errorCode?, originalError?);
407 Proxy Authentication Required
ProxyAuthenticationRequired(message?, errorCode?, originalError?);
408 Request Timeout
RequestTimeout(message?, errorCode?, originalError?);
409 Conflict
Conflict(message?, errorCode?, originalError?);
410 Gone
Gone(message?, errorCode?, originalError?);
422 Unprocessable Entity
UnprocessableEntity(message?, errorCode?, originalError?);
424 Failed Dependency
FailedDependency(message?, errorCode?, originalError?);
500 Internal Server Error
InternalServerError(message?, errorCode?, originalError?);
501 Not Implemented
NotImplemented(message?, errorCode?, originalError?);
502 Bad Gateway
BadGateway(message?, errorCode?, originalError?);
503 Service Unavailable
ServiceUnavailable(message?, errorCode?, originalError?);
504 Gateway Timeout
GatewayTimeout(message?, errorCode?, originalError?);
505 HTTP Version Not Supported
HttpVersionNotSupported(message?, errorCode?, originalError?);
511 Network Authentication Required
NetworkAuthenticationRequired(message?, errorCode?, originalError?);
TODO
- Implement more Error Classes
관련 프로젝트 살펴보기
불러오는 중…