-
Notifications
You must be signed in to change notification settings - Fork 20
fix: surface ServiceResponseError outside of RuntimeError #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
bfde218
to
2721200
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just had some suggested improvements to the test cases.
// Calling authenticate should result in an exception. | ||
try { | ||
authenticator.authenticate(requestBuilder); | ||
fail("Expected authenticate() to result in exception!"); | ||
} catch (RuntimeException excp) { | ||
Throwable causedBy = excp.getCause(); | ||
assertNotNull(causedBy); | ||
assertTrue(causedBy instanceof ServiceResponseException); | ||
assertFalse(causedBy instanceof ServiceResponseException); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to check for the specific exception type that we'd expect in this "bad json response" scenario (i.e. a JsonParseException), rather than just make sure it's not a ServiceResponseException.
try { | ||
authenticator.authenticate(requestBuilder); | ||
fail("Expected authenticate() to result in exception!"); | ||
} catch (RuntimeException excp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} catch (RuntimeException excp) { | |
} catch (ServiceResponseException excp) { |
You could just catch the ServiceResponseException directly and call that a success, while anything else (the Throwable catch clause) would be an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should remain RuntimeExcpetion
here, since the underlying error is IllegalStateException from the bad JSON. The ServiceResponse Exception changes have been made in both the testApiErrorBadRequest()
locations where it is now surfaced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just testing you :) HAHAHA
try { | ||
authenticator.authenticate(requestBuilder); | ||
fail("Expected authenticate() to result in exception!"); | ||
} catch (RuntimeException excp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} catch (RuntimeException excp) { | |
} catch (ServiceResponseException excp) { |
Same comment as above.
@@ -348,7 +373,8 @@ public void testApiErrorBadRequest() throws Throwable { | |||
} catch (RuntimeException excp) { | |||
Throwable causedBy = excp.getCause(); | |||
assertNotNull(causedBy); | |||
assertTrue(causedBy instanceof ServiceResponseException); | |||
assertFalse(causedBy instanceof ServiceResponseException); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertFalse(causedBy instanceof ServiceResponseException); | |
assertTrue(causedBy instanceof JsonParseException); |
@@ -348,7 +373,8 @@ public void testApiErrorBadRequest() throws Throwable { | |||
} catch (RuntimeException excp) { | |||
Throwable causedBy = excp.getCause(); | |||
assertNotNull(causedBy); | |||
assertTrue(causedBy instanceof ServiceResponseException); | |||
assertFalse(causedBy instanceof ServiceResponseException); | |||
assertFalse(excp instanceof ServiceResponseException); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertFalse(excp instanceof ServiceResponseException); |
I don't think this is needed if we correctly test the happy path.
2721200
to
e06c1fb
Compare
e06c1fb
to
aa73a11
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
try { | ||
authenticator.authenticate(requestBuilder); | ||
fail("Expected authenticate() to result in exception!"); | ||
} catch (RuntimeException excp) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just testing you :) HAHAHA
## [8.4.3](8.4.2...8.4.3) (2020-07-29) ### Bug Fixes * surface ServiceResponseError outside of RuntimeError ([#83](#83)) ([349ca1a](349ca1a))
🎉 This PR is included in version 8.4.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This PR will allow ServiceResponseErrors to be returned directly, as opposed to in the
causedBy:
of a RuntimeException.