Skip to content
This repository was archived by the owner on May 28, 2023. It is now read-only.

Commit 0bc6bf3

Browse files
author
tkostuch
committed
add error status code as number
1 parent c333ce9 commit 0bc6bf3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/api/catalog.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ export default ({config, db}) => async function (req, res, body) {
118118
auth: auth
119119
}, async (_err, _res, _resBody) => { // TODO: add caching layer to speed up SSR? How to invalidate products (checksum on the response BEFORE processing it)
120120
if (_err || _resBody.error) {
121+
console.error(_err || _resBody.error)
121122
apiError(res, _err || _resBody.error)
122123
return
123124
}

src/lib/util.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ export function apiStatus (res, result = 'OK', code = 200, meta = null) {
8686
* @return {json} [result='OK'] Text message or result information object
8787
*/
8888
export function apiError (res, error) {
89-
let errorCode = error.code || error.status || 500;
89+
let errorCode = error.code || error.status;
9090
let errorMessage = error.errorMessage || error;
9191
if (error instanceof Error) {
9292
// Class 'Error' is not serializable with JSON.stringify, extract data explicitly.
9393
errorCode = error.code || errorCode;
9494
errorMessage = error.message;
9595
}
96-
return apiStatus(res, errorMessage, errorCode);
96+
return apiStatus(res, errorMessage, Number(errorCode) || 500);
9797
}
9898

9999
export function encryptToken (textToken, secret) {

0 commit comments

Comments
 (0)