@vitrical/utils
Advanced tools
Comparing version 1.5.5 to 1.5.6
export declare class ApiError extends Error { | ||
url: string; | ||
status: number; | ||
body: any; | ||
headers: { | ||
@@ -6,0 +5,0 @@ [key: string]: any; |
@@ -76,3 +76,2 @@ "use strict"; | ||
const apiError = new ApiError(message); | ||
apiError.body = 'data' in err.response ? err.response.data : err.response; | ||
apiError.headers = | ||
@@ -79,0 +78,0 @@ 'headers' in err.response && |
@@ -12,16 +12,5 @@ "use strict"; | ||
const forwarded = req.headers['x-forwarded-for'] || req.ip || req.socket.remoteAddress; | ||
console.error(`${method} ${path} from ${forwarded} errored`); | ||
if (err instanceof api_1.ApiError) { | ||
console.error(err.message); | ||
console.error(err.stack); | ||
console.error(`${method} ${path} from ${forwarded} errored: `, err.status, err.msg || err.message, err.stack); | ||
res.status(err.status).send({ | ||
msg: err.message + `\nat ${err.url}\n`, | ||
body: err.body, | ||
}); | ||
return; | ||
} | ||
else if (typeof err === 'object' && 'message' in err && 'stack' in err) { | ||
console.error(err.message); | ||
console.error(err.stack); | ||
res.status(500).send({ | ||
msg: err.message + '', | ||
@@ -31,6 +20,10 @@ }); | ||
} | ||
console.error(err); | ||
if (typeof err === 'object' && !!err && 'stack' in err && typeof err.stack === 'string') { | ||
console.error(`${method} ${path} from ${forwarded} errored: `, err, err.stack); | ||
} | ||
else { | ||
console.error(`${method} ${path} from ${forwarded} errored: `, err); | ||
} | ||
res.status(500).send({ | ||
msg: 'An unexpected error has occured', | ||
err, | ||
}); | ||
@@ -37,0 +30,0 @@ }; |
{ | ||
"name": "@vitrical/utils", | ||
"version": "1.5.5", | ||
"version": "1.5.6", | ||
"description": "Collection of useful functions and typings", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
47995
722