aboutsummaryrefslogtreecommitdiff
path: root/src/services/errors
diff options
context:
space:
mode:
authortaehoon <th.dev91@gmail.com>2019-02-26 12:26:04 -0500
committertaehoon <th.dev91@gmail.com>2019-02-26 12:26:04 -0500
commitb78227456ea6b1a80cd85988d3ef91cb654a881c (patch)
tree602ae896a74fb55a0a7ed6ebd14413a60809e53a /src/services/errors
parente687b58091bcedb6f3a56d94030fa312e51830d5 (diff)
Better error handling
Diffstat (limited to 'src/services/errors')
-rw-r--r--src/services/errors/errors.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/services/errors/errors.js b/src/services/errors/errors.js
new file mode 100644
index 00000000..548f3c68
--- /dev/null
+++ b/src/services/errors/errors.js
@@ -0,0 +1,14 @@
+export function StatusCodeError (statusCode, body, options, response) {
+ this.name = 'StatusCodeError'
+ this.statusCode = statusCode
+ this.message = statusCode + ' - ' + (JSON && JSON.stringify ? JSON.stringify(body) : body)
+ this.error = body // legacy attribute
+ this.options = options
+ this.response = response
+
+ if (Error.captureStackTrace) { // required for non-V8 environments
+ Error.captureStackTrace(this)
+ }
+}
+StatusCodeError.prototype = Object.create(Error.prototype)
+StatusCodeError.prototype.constructor = StatusCodeError