UNPKG

2.2 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.noContent = exports.created = exports.ok = exports.requestTimeout = exports.notFound = exports.internalServerError = exports.unauthorized = exports.forbidden = exports.badRequest = void 0;
4const http2_1 = require("http2");
5const error_1 = require("./error");
6function badRequest(details) {
7 const error = new error_1.BadRequestError(details);
8 return buildResult(error, http2_1.constants.HTTP_STATUS_BAD_REQUEST);
9}
10exports.badRequest = badRequest;
11function forbidden(details) {
12 const error = new error_1.ForbiddenError(details);
13 return buildResult(error, http2_1.constants.HTTP_STATUS_FORBIDDEN);
14}
15exports.forbidden = forbidden;
16function unauthorized(details) {
17 const error = new error_1.UnauthorizedError(details);
18 return buildResult(error, http2_1.constants.HTTP_STATUS_UNAUTHORIZED);
19}
20exports.unauthorized = unauthorized;
21function internalServerError() {
22 const error = new error_1.InternalServerError("InternalServerError");
23 return buildResult(error, http2_1.constants.HTTP_STATUS_INTERNAL_SERVER_ERROR);
24}
25exports.internalServerError = internalServerError;
26function notFound(details) {
27 const error = new error_1.NotFoundError(details);
28 return buildResult(error, http2_1.constants.HTTP_STATUS_NOT_FOUND);
29}
30exports.notFound = notFound;
31function requestTimeout(details) {
32 const error = new error_1.RequestTimeoutError(details);
33 return buildResult(error, http2_1.constants.HTTP_STATUS_REQUEST_TIMEOUT);
34}
35exports.requestTimeout = requestTimeout;
36function ok(result) {
37 return buildResult(result, http2_1.constants.HTTP_STATUS_OK);
38}
39exports.ok = ok;
40function created(result) {
41 return buildResult(result, http2_1.constants.HTTP_STATUS_CREATED);
42}
43exports.created = created;
44function noContent() {
45 return buildResult(null, http2_1.constants.HTTP_STATUS_NO_CONTENT);
46}
47exports.noContent = noContent;
48function buildResult(result, statusCode) {
49 const body = result && result instanceof error_1.LambdaHandlerError
50 ? { errors: [{ name: result.name, details: result.details }] }
51 : result;
52 return {
53 body,
54 statusCode,
55 };
56}