-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
45 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"presets": [ | ||
["env", { | ||
"targets": { | ||
"node": 7.7 | ||
"node": "7.8" | ||
}, | ||
"include": [], | ||
"useBuiltIns": true, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
|
||
const RE_DATA = /(.*)\[\[(.+?)\]\](.*)/; | ||
|
||
export default function errorResponse(req, res) { | ||
const requestId = req.get('Request-Id'); | ||
return (err = new Error('UNDEFINED ERROR')) => { | ||
let data = err; | ||
const message = err.message | ||
.replace(RE_DATA, ($0, before, json = '', after) => { | ||
try { | ||
data = JSON.parse(json) || {}; | ||
} catch (ex) { | ||
data = err; | ||
} | ||
return before + after; | ||
}); | ||
if (!data.isExpected) { | ||
if (process.env.NODE_ENV === 'production') { | ||
logger.error(`[Request-Id: ${requestId}]`, err); | ||
} else { | ||
console.error(requestId, err); | ||
} | ||
const requestId = res.get('Request-Id'); | ||
return (err = {}) => { | ||
const { | ||
status = -100, | ||
isExpected, | ||
message = 'UNDEFINED ERROR', | ||
meta = {}, | ||
} = err; | ||
if (!isExpected) { | ||
logger.error(`[${requestId}] ${status} | ${message}`, meta); | ||
} | ||
res.json({ | ||
status: data.status || -100, | ||
status, | ||
message, | ||
meta, | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters