Throwing object/string literals is considered a bad practice, and we've had an incident today that would've been avoided if voucherify-sdk was throwing error objects instead of object literals because error objects offer useful fields for debugging such as stack it makes things easier.
This PR makes the SDK throw errors that extend the JS error constructor and copy all the fields from the body to the instance error, making all tests pass.
One thing to consider is the fact that in line 8 in VoucherifyError.js we're assigning all values from body to this which can overwrite one of the instance properties:
message
description
number
name
fileName
lineNumber
columnNumber
stack
I suppose overwriting the first 3 is okay and is intended, however overwriting the stack could be undesired since it's basically the main purpose of this PR.
Throwing object/string literals is considered a bad practice, and we've had an incident today that would've been avoided if voucherify-sdk was throwing error objects instead of object literals because error objects offer useful fields for debugging such as
stack
it makes things easier.This PR makes the SDK throw errors that extend the JS error constructor and copy all the fields from the body to the instance error, making all tests pass.
One thing to consider is the fact that in line 8 in VoucherifyError.js we're assigning all values from
body
tothis
which can overwrite one of the instance properties:I suppose overwriting the first 3 is okay and is intended, however overwriting the
stack
could be undesired since it's basically the main purpose of this PR.