Skip to content

Commit

Permalink
Refactor: Replaced error.errors with .reason
Browse files Browse the repository at this point in the history
This is more standard and will be printed in the console
  • Loading branch information
fvdm committed Dec 14, 2023
1 parent eda23dd commit de8d216
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions nsapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,25 @@ module.exports = class NSAPI {

// Normal API error
if ( data.code && data.message ) {
error = new Error( data.message );
error = new Error( `API: ${data.message}` );
error.code = data.code;
error.errors = data.errors;
error.reason = data.errors;
throw error;
}

// API field error - hard to replicate
/* istanbul ignore next */
if ( data.fieldErrors && data.fieldErrors.length ) {
error = new Error( 'API field error' );
error.errors = data.fieldErrors;
error.reason = data.fieldErrors;
throw error;
}

// API error without message - hard to replicate
/* istanbul ignore next */
if ( data.errors && data.errors[0] ) {
error = new Error( 'API error' );
error.errors = data.errors;
error.reason = data.errors;
throw error;
}

Expand Down

0 comments on commit de8d216

Please sign in to comment.