Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem does the pull request solve?
Exceptions in Ruby return the exception message when calling
#to_s
on it:Because this is default behaviour, libraries sometimes depend on
to_s
to get a readable version of the exception message. For example, the Sentry client does it to give the exception a name:https://github.com/getsentry/raven-ruby/blob/065cf973cb0ad3672d0d213e80b6e8a9a8e6f8cb/lib/raven/event.rb#L144
Currently, Sentry reports do not show the error message set when raising the exception - it only displays
Notifications::Client::BadRequestError
:This is because we’re only defining
RequestError#message
. This is apparently not the same as initialising an exception with a message, as you can see here:The issue was introduced in #73 / #72, which removed the explicit
to_s
method.This commit fixes the issue by constructing the message in the constructor. Note that we’ve renamed the
message
method, but callinge.message
still works because it’s part of the exception interface.Another option would be to add the
to_s
method back (like we experimented with in DFE-Digital/apply-for-teacher-training#1024), but this solution seems the most Ruby-esque and relies on less knowledge of Exception internals.After DFE-Digital/apply-for-teacher-training#1024, the exceptions are properly reported:
This change is backwards compatible.
Checklist
DOCUMENTATION.md
)lib/notifications/client/version.rb
)