1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.RestHttpErrors = void 0;
|
8 | const tslib_1 = require("tslib");
|
9 | const http_errors_1 = tslib_1.__importDefault(require("http-errors"));
|
10 | var RestHttpErrors;
|
11 | (function (RestHttpErrors) {
|
12 | function invalidData(data, name, extraProperties) {
|
13 | const msg = `Invalid data ${JSON.stringify(data)} for parameter "${name}".`;
|
14 | return Object.assign(new http_errors_1.default.BadRequest(msg), {
|
15 | code: 'INVALID_PARAMETER_VALUE',
|
16 | parameterName: name,
|
17 | }, extraProperties);
|
18 | }
|
19 | RestHttpErrors.invalidData = invalidData;
|
20 | function unsupportedMediaType(contentType, allowedTypes = []) {
|
21 | const msg = (allowedTypes === null || allowedTypes === void 0 ? void 0 : allowedTypes.length)
|
22 | ? `Content-type ${contentType} does not match [${allowedTypes}].`
|
23 | : `Content-type ${contentType} is not supported.`;
|
24 | return Object.assign(new http_errors_1.default.UnsupportedMediaType(msg), {
|
25 | code: 'UNSUPPORTED_MEDIA_TYPE',
|
26 | contentType: contentType,
|
27 | allowedMediaTypes: allowedTypes,
|
28 | });
|
29 | }
|
30 | RestHttpErrors.unsupportedMediaType = unsupportedMediaType;
|
31 | function missingRequired(name) {
|
32 | const msg = `Required parameter ${name} is missing!`;
|
33 | return Object.assign(new http_errors_1.default.BadRequest(msg), {
|
34 | code: 'MISSING_REQUIRED_PARAMETER',
|
35 | parameterName: name,
|
36 | });
|
37 | }
|
38 | RestHttpErrors.missingRequired = missingRequired;
|
39 | function invalidParamLocation(location) {
|
40 | const msg = `Parameters with "in: ${location}" are not supported yet.`;
|
41 | return new http_errors_1.default.NotImplemented(msg);
|
42 | }
|
43 | RestHttpErrors.invalidParamLocation = invalidParamLocation;
|
44 | RestHttpErrors.INVALID_REQUEST_BODY_MESSAGE = 'The request body is invalid. See error object `details` property for more info.';
|
45 | function invalidRequestBody(details) {
|
46 | return Object.assign(new http_errors_1.default.UnprocessableEntity(RestHttpErrors.INVALID_REQUEST_BODY_MESSAGE), {
|
47 | code: 'VALIDATION_FAILED',
|
48 | details,
|
49 | });
|
50 | }
|
51 | RestHttpErrors.invalidRequestBody = invalidRequestBody;
|
52 | })(RestHttpErrors || (exports.RestHttpErrors = RestHttpErrors = {}));
|
53 |
|
\ | No newline at end of file |