Skip to content

Commit

Permalink
Only throw an error on a missing requestId on 200 level responses
Browse files Browse the repository at this point in the history
see #38
  • Loading branch information
jcberquist committed Jan 27, 2022
1 parent a2a702b commit f77f707
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion stripe.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ component {

if ( structKeyExists( response.headers, 'Request-Id' ) ) {
response[ 'requestId' ] = response.headers[ 'Request-Id' ];
} else {
} else if ( int( response.status ) >= 200 && int( response.status ) < 300 ) {
throw(
type = 'StripeResponseException',
message = 'Request-Id is missing from the response headers',
Expand Down
22 changes: 21 additions & 1 deletion tests/specs/apiCallResponseSpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ component extends=testbox.system.BaseSpec {
httpService.$reset();
} );

it( 'throws an error when the Request-Id header is missing', function() {
it( 'throws an error when the Request-Id header is missing on a 200 request', function() {
httpService.$(
'exec',
{
Expand All @@ -42,6 +42,26 @@ component extends=testbox.system.BaseSpec {
regex = 'Request-Id is missing from the response headers'
);
} );

it( 'does not throw an error when the Request-Id header is missing on a non 200 request', function() {
httpService.$(
'exec',
{
responseHeader: {
'Content-Type': 'application/json'
},
statuscode: '401 Not Authorized',
filecontent: '{}'
}
);

expect( function() {
res = stripe.accounts.retrieve();
} ).notToThrow(
type = 'StripeResponseException',
regex = 'Request-Id is missing from the response headers'
);
} );
} );
}

Expand Down

0 comments on commit f77f707

Please sign in to comment.