Skip to content

Commit f743815

Browse files
committed
Hack to ensure error structures don't cause crash
In json.ErrorResponse object, the structure of the object is different based on the type of error Authorize.Net throws. It's not a good practice to assume the structure will always be the exact same. This is a temporary quick fix and not a permanent solution.
1 parent d535163 commit f743815

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Diff for: lib/AuthorizeNetGateway.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,20 @@ function createJsonCallback (cb) {
8080
var json = result;
8181

8282
if (json.ErrorResponse) {
83-
throw new GatewayError(json.ErrorResponse[0].messages[0].message[0].text[0], json.ErrorResponse[0]);
83+
if (
84+
json.ErrorResponse[0] &&
85+
json.ErrorResponse[0].messages &&
86+
json.ErrorResponse[0].messages[0] &&
87+
json.ErrorResponse[0].messages[0].message &&
88+
json.ErrorResponse[0].messages[0].message[0] &&
89+
json.ErrorResponse[0].messages[0].message[0].text &&
90+
json.ErrorResponse[0].messages[0].message[0].text[0]
91+
) {
92+
throw new GatewayError(json.ErrorResponse[0].messages[0].message[0].text[0], json.ErrorResponse[0]);
93+
}
94+
else {
95+
throw new GatewayError(JSON.stringify(json.ErrorResponse));
96+
}
8497
}
8598

8699
return cb(json);

0 commit comments

Comments
 (0)