Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/jobs/get_usps_proofing_results_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def handle_bad_request_error(err, enrollment)
when IPP_EXPIRED_ERROR_MESSAGE
handle_expired_status_update(enrollment, err.response)
else
NewRelic::Agent.notice_error(err)
analytics(user: enrollment.user).idv_in_person_usps_proofing_results_job_exception(
**enrollment_analytics_attributes(enrollment, complete: false),
**response_analytics_attributes(response),
Expand Down
27 changes: 26 additions & 1 deletion spec/jobs/get_usps_proofing_results_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,32 @@
)
end

context 'when USPS returns a 4xx status code' do
context 'when USPS returns an unexpected 400 status code' do
before(:each) do
stub_request_proofing_results_with_responses(
{
status: 400,
body: { 'responseMessage' => 'This USPS location has closed 😭' }.to_json,
},
)
end

it_behaves_like(
'enrollment_encountering_an_exception',
exception_class: 'Faraday::BadRequestError',
exception_message: 'the server responded with status 400',
response_message: 'This USPS location has closed 😭',
response_status_code: 400,
)

it 'logs the error to NewRelic' do
expect(NewRelic::Agent).to receive(:notice_error).
with(instance_of(Faraday::BadRequestError))
job.perform(Time.zone.now)
end
Comment on lines +588 to +592
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we want "logs the error to NewRelic" to be an assertion as part of the shared example set enrollment_encountering_an_exception ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that makes sense. The only downside is it's a little complicated to make the example set know which type of error NewRelic::Agent#receive should be called with so I lean towards just expecting the method to be called and not specifying the error type it should receive

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually there are a couple of error types which we aren't currently reporting to NewRelic, such as if USPS returns something to us other than a hash when we expect a hash. I don't know if it's useful to log those to NewRelic...I guess we could construct a StandardError with some error string content

I'm now leaning towards leaving it out of the example set, how it is right now

end

context 'when USPS returns a >400 status code' do
before(:each) do
stub_request_proofing_results_with_responses(
{
Expand Down