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

Commit d9cd852

Browse files
authored
Merge pull request #472 from gibkigonzo/bugfix/442
add error status code as number in apiError
2 parents 54f63f4 + 542a050 commit d9cd852

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12-
- get proper tax calculation for multistore - @didkan (#464)
13-
- create only one ES client instance per app - @gibkigonzo (#393)
14-
12+
- AAdd error status code as number in `apiError` - @gibkigonzo (#442)
13+
- Get proper tax calculation for multistore - @didkan (#464)
14+
- Create only one ES client instance per app - @gibkigonzo (#393)
1515

1616
## [1.12.0] - 2020.06.01
1717

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)