UNPKG

2.61 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
3// Node module: @loopback/rest
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.RestHttpErrors = void 0;
8const tslib_1 = require("tslib");
9const http_errors_1 = tslib_1.__importDefault(require("http-errors"));
10var 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 || (exports.RestHttpErrors = {}));
53//# sourceMappingURL=rest-http-error.js.map
\No newline at end of file