This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Errors not captured properly handling 4XX or 5XX response codes #91
Comments
And the example output from watch in JS debugger:
second time through |
Looks like line 118 of Resource.js parses _responseHandler: function(req, callback) {
var self = this;
return function(res) {
// console.log('status %s', res.statusCode);
var response = '';
res.setEncoding('utf8');
res.on('data', function(chunk) {
response += chunk;
});
res.on('end', function() {
var err;
var errData = {
detail: response,
path: req.path,
statusCode: res.statusCode
};
try {
response = JSON.parse(response);
} catch (e) {
errData.message = "Invalid JSON received from the Shippo API";
return callback.call(
self,
new Error.ShippoAPIError(errData),
null
);
}
/***********************************************
* NO 403 Handler below (or other codes)
* resulting error is misshaped
* which consumers' downstream calls are unable to check for an error response
***********************************************/
if (res.statusCode === 401) {
errData.message = "Invalid credentials";
err = new Error.ShippoAuthenticationError(errData);
} else if (res.statusCode === 404) {
errData.message = "Item not found";
err = new Error.ShippoNotFoundError(errData);
} else if (res.statusCode === 301) {
errData.message = "API sent us a 301 redirect, stopping call. Please contact our tech team and provide them with the operation that caused this error.";
err = new Error.ShippoAPIError(errData);
} else if (res.statusCode === 400) {
errData.message = "The data you sent was not accepted as valid";
err = new Error.ShippoAPIError(errData);
}
if (err) {
return callback.call(self, err, null);
} else {
// 403 and 500 errors fall through as a success response here because 'err' is still undefined after if-else flow
callback.call(self, null, response);
}
});
};
}, |
jbool24
changed the title
Duplicate Request errors
Duplicate Request or Errors not captured properly handling 4XX or 5XX response codes
May 31, 2023
jbool24
changed the title
Duplicate Request or Errors not captured properly handling 4XX or 5XX response codes
Errors not captured properly handling 4XX or 5XX response codes
Jun 3, 2023
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
When using the debugger during a call with
shippo.transaction.create({{PAYLOAD}})
, the request seems to fire twice. The first time with a valid payload describing the response, and the second payload only contains{ details: 'Permission Denied' }
. This breaks a previous contract that says there will be astatus
field on the response object.This code is contained in
Method.js
on line 79.To recreate, simply add a breakpoint on this line and use the function call
shippo.transactions.create()
method to see the request fire twice.The text was updated successfully, but these errors were encountered: