http-response-helper
Version:
HTTP-Response-Helper is a utility library for sending HTTP responses with the correct status code.
46 lines (45 loc) • 2.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HttpResponseHelper = void 0;
const HttpStatusCodes_1 = require("./utilities/HttpStatusCodes");
const createHttpResponse = (statusCodeKey) => (response, data, message) => {
response.status(HttpStatusCodes_1.HttpStatusCodes[statusCodeKey].code).json({
code: HttpStatusCodes_1.HttpStatusCodes[statusCodeKey].code,
data,
message: message || HttpStatusCodes_1.HttpStatusCodes[statusCodeKey].status,
});
};
exports.HttpResponseHelper = {
CONTINUE: createHttpResponse("CONTINUE"),
SWITCHING_PROTOCOLS: createHttpResponse("SWITCHING_PROTOCOLS"),
PROCESSING: createHttpResponse("PROCESSING"),
EARLY_HINTS: createHttpResponse("EARLY_HINTS"),
UPLOAD_RESUMPTION_SUPPORTED: createHttpResponse("UPLOAD_RESUMPTION_SUPPORTED"),
OK: createHttpResponse("OK"),
CREATED: createHttpResponse("CREATED"),
ACCEPTED: createHttpResponse("ACCEPTED"),
NON_AUTHORITATIVE_INFORMATION: createHttpResponse("NON_AUTHORITATIVE_INFORMATION"),
NO_CONTENT: createHttpResponse("NO_CONTENT"),
RESET_CONTENT: createHttpResponse("RESET_CONTENT"),
PARTIAL_CONTENT: createHttpResponse("PARTIAL_CONTENT"),
MULTI_STATUS: createHttpResponse("MULTI_STATUS"),
ALREADY_REPORTED: createHttpResponse("ALREADY_REPORTED"),
IM_USED: createHttpResponse("IM_USED"),
MULTIPLE_CHOICES: createHttpResponse("MULTIPLE_CHOICES"),
MOVED_PERMANENTLY: createHttpResponse("MOVED_PERMANENTLY"),
FOUND: createHttpResponse("FOUND"),
SEE_OTHER: createHttpResponse("SEE_OTHER"),
NOT_MODIFIED: createHttpResponse("NOT_MODIFIED"),
TEMPORARY_REDIRECT: createHttpResponse("TEMPORARY_REDIRECT"),
PERMANENT_REDIRECT: createHttpResponse("PERMANENT_REDIRECT"),
BAD_REQUEST: createHttpResponse("BAD_REQUEST"),
UNAUTHORIZED: createHttpResponse("UNAUTHORIZED"),
FORBIDDEN: createHttpResponse("FORBIDDEN"),
NOT_FOUND: createHttpResponse("NOT_FOUND"),
CONFLICT: createHttpResponse("CONFLICT"),
INTERNAL_SERVER_ERROR: createHttpResponse("INTERNAL_SERVER_ERROR"),
NOT_IMPLEMENTED: createHttpResponse("NOT_IMPLEMENTED"),
BAD_GATEWAY: createHttpResponse("BAD_GATEWAY"),
SERVICE_UNAVAILABLE: createHttpResponse("SERVICE_UNAVAILABLE"),
GATEWAY_TIMEOUT: createHttpResponse("GATEWAY_TIMEOUT"),
};