1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.noContent = exports.created = exports.ok = exports.requestTimeout = exports.notFound = exports.internalServerError = exports.unauthorized = exports.forbidden = exports.badRequest = void 0;
|
4 | const http2_1 = require("http2");
|
5 | const error_1 = require("./error");
|
6 | function badRequest(details) {
|
7 | const error = new error_1.BadRequestError(details);
|
8 | return buildResult(error, http2_1.constants.HTTP_STATUS_BAD_REQUEST);
|
9 | }
|
10 | exports.badRequest = badRequest;
|
11 | function forbidden(details) {
|
12 | const error = new error_1.ForbiddenError(details);
|
13 | return buildResult(error, http2_1.constants.HTTP_STATUS_FORBIDDEN);
|
14 | }
|
15 | exports.forbidden = forbidden;
|
16 | function unauthorized(details) {
|
17 | const error = new error_1.UnauthorizedError(details);
|
18 | return buildResult(error, http2_1.constants.HTTP_STATUS_UNAUTHORIZED);
|
19 | }
|
20 | exports.unauthorized = unauthorized;
|
21 | function internalServerError() {
|
22 | const error = new error_1.InternalServerError("InternalServerError");
|
23 | return buildResult(error, http2_1.constants.HTTP_STATUS_INTERNAL_SERVER_ERROR);
|
24 | }
|
25 | exports.internalServerError = internalServerError;
|
26 | function notFound(details) {
|
27 | const error = new error_1.NotFoundError(details);
|
28 | return buildResult(error, http2_1.constants.HTTP_STATUS_NOT_FOUND);
|
29 | }
|
30 | exports.notFound = notFound;
|
31 | function requestTimeout(details) {
|
32 | const error = new error_1.RequestTimeoutError(details);
|
33 | return buildResult(error, http2_1.constants.HTTP_STATUS_REQUEST_TIMEOUT);
|
34 | }
|
35 | exports.requestTimeout = requestTimeout;
|
36 | function ok(result) {
|
37 | return buildResult(result, http2_1.constants.HTTP_STATUS_OK);
|
38 | }
|
39 | exports.ok = ok;
|
40 | function created(result) {
|
41 | return buildResult(result, http2_1.constants.HTTP_STATUS_CREATED);
|
42 | }
|
43 | exports.created = created;
|
44 | function noContent() {
|
45 | return buildResult(null, http2_1.constants.HTTP_STATUS_NO_CONTENT);
|
46 | }
|
47 | exports.noContent = noContent;
|
48 | function 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 | }
|