Skip to content

Commit 4fedf14

Browse files
author
Shogun
committed
chore: Rebuild.
1 parent 500d466 commit 4fedf14

File tree

5 files changed

+66
-331
lines changed

5 files changed

+66
-331
lines changed

lib/errors.js

Lines changed: 0 additions & 156 deletions
This file was deleted.

lib/index.js

Lines changed: 56 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,61 @@
1-
'use strict'
2-
function __export(m) {
3-
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]
4-
}
5-
var __importDefault =
6-
(this && this.__importDefault) ||
7-
function(mod) {
8-
return mod && mod.__esModule ? mod : { default: mod }
9-
}
10-
Object.defineProperty(exports, '__esModule', { value: true })
11-
const fastify_plugin_1 = __importDefault(require('fastify-plugin'))
12-
const http_errors_1 = require('http-errors')
13-
const http_status_codes_1 = require('http-status-codes')
14-
const statuses_1 = __importDefault(require('statuses'))
15-
const properties_1 = require('./properties')
16-
__export(require('./errors'))
17-
var properties_2 = require('./properties')
18-
exports.addAdditionalProperties = properties_2.addAdditionalProperties
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
const fastify_plugin_1 = __importDefault(require("fastify-plugin"));
7+
const http_errors_1 = require("http-errors");
8+
const http_status_codes_1 = require("http-status-codes");
9+
const statuses_1 = __importDefault(require("statuses"));
10+
const properties_1 = require("./properties");
11+
var properties_2 = require("./properties");
12+
exports.addAdditionalProperties = properties_2.addAdditionalProperties;
1913
function handleNotFoundError(request, reply) {
20-
handleErrors(new http_errors_1.NotFound('Not found.'), request, reply)
14+
handleErrors(new http_errors_1.NotFound('Not found.'), request, reply);
2115
}
22-
exports.handleNotFoundError = handleNotFoundError
16+
exports.handleNotFoundError = handleNotFoundError;
2317
function handleErrors(error, request, reply) {
24-
var _a
25-
// It is a generic error, handle it
26-
if (!('statusCode' in error)) {
27-
// It is requested to hide the error, just log it and then create a generic one
28-
if ((_a = request.errorProperties) === null || _a === void 0 ? void 0 : _a.hideUnhandledErrors) {
29-
request.log.error({ error: properties_1.serializeError(error) })
30-
error = new http_errors_1.InternalServerError('An error occurred trying to process your request.')
31-
} else {
32-
// Wrap in a http-error, making the stack explicitily available
33-
error = Object.assign(new http_errors_1.InternalServerError(error.message), properties_1.serializeError(error))
34-
Object.defineProperty(error, 'stack', { enumerable: true })
18+
var _a;
19+
// It is a generic error, handle it
20+
if (!('statusCode' in error)) {
21+
// It is requested to hide the error, just log it and then create a generic one
22+
if ((_a = request.errorProperties) === null || _a === void 0 ? void 0 : _a.hideUnhandledErrors) {
23+
request.log.error({ error: properties_1.serializeError(error) });
24+
error = new http_errors_1.InternalServerError('An error occurred trying to process your request.');
25+
}
26+
else {
27+
// Wrap in a http-error, making the stack explicitily available
28+
error = Object.assign(new http_errors_1.InternalServerError(error.message), properties_1.serializeError(error));
29+
Object.defineProperty(error, 'stack', { enumerable: true });
30+
}
31+
}
32+
// Get the status code
33+
let { statusCode, headers } = error;
34+
// Code outside HTTP range
35+
if (statusCode < 100 || statusCode > 599) {
36+
statusCode = http_status_codes_1.INTERNAL_SERVER_ERROR;
3537
}
36-
}
37-
// Get the status code
38-
let { statusCode, headers } = error
39-
// Code outside HTTP range
40-
if (statusCode < 100 || statusCode > 599) {
41-
statusCode = http_status_codes_1.INTERNAL_SERVER_ERROR
42-
}
43-
// Create the body
44-
const body = {
45-
statusCode,
46-
code: error.code,
47-
error: statuses_1.default[statusCode.toString()],
48-
message: error.message
49-
}
50-
properties_1.addAdditionalProperties(body, error)
51-
// Send the error back
52-
reply
53-
.code(statusCode)
54-
.headers(headers || {})
55-
.type('application/json')
56-
.send(body)
38+
// Create the body
39+
const body = {
40+
statusCode,
41+
code: error.code,
42+
error: statuses_1.default[statusCode.toString()],
43+
message: error.message
44+
};
45+
properties_1.addAdditionalProperties(body, error);
46+
// Send the error back
47+
reply
48+
.code(statusCode)
49+
.headers(headers || {})
50+
.type('application/json')
51+
.send(body);
5752
}
58-
exports.handleErrors = handleErrors
59-
exports.default = fastify_plugin_1.default(
60-
function(instance, options, done) {
61-
var _a
62-
const hideUnhandledErrors =
63-
((_a = options.hideUnhandledErrors), _a !== null && _a !== void 0 ? _a : process.env.NODE_ENV === 'production')
64-
instance.decorateRequest('errorProperties', { hideUnhandledErrors })
65-
instance.setErrorHandler(handleErrors)
66-
instance.setNotFoundHandler(handleNotFoundError)
67-
done()
68-
},
69-
{ name: 'fastify-errors-properties' }
70-
)
53+
exports.handleErrors = handleErrors;
54+
exports.default = fastify_plugin_1.default(function (instance, options, done) {
55+
var _a;
56+
const hideUnhandledErrors = (_a = options.hideUnhandledErrors, (_a !== null && _a !== void 0 ? _a : process.env.NODE_ENV === 'production'));
57+
instance.decorateRequest('errorProperties', { hideUnhandledErrors });
58+
instance.setErrorHandler(handleErrors);
59+
instance.setNotFoundHandler(handleNotFoundError);
60+
done();
61+
}, { name: 'fastify-errors-properties' });

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"postpublish": "git push origin && git push origin -f --tags"
3737
},
3838
"dependencies": {
39-
"fast-json-stringify": "^1.15.6",
4039
"fastify-plugin": "^1.6.0",
4140
"http-errors": "^1.7.3",
4241
"http-status-codes": "^1.4.0",
@@ -45,7 +44,6 @@
4544
"devDependencies": {
4645
"@cowtech/tslint-config": "^5.13.0",
4746
"@types/http-errors": "^1.6.2",
48-
"@types/http-status-codes": "^1.2.0",
4947
"@types/jest": "^24.0.23",
5048
"@types/node": "^12.12.8",
5149
"@types/statuses": "^1.5.0",

types/errors.d.ts

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)