Parse all RabbitMQ Management API responses for errors. #152
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.
Here is the PR for #151.
What does this PR do?
Parses the response body for all RabbitMQ Management API requests, not just
GET
requests, returning anerror
if one exists.This provides a more consistent experience for the end user, as well as providing valuable diagnostic information for RabbitMQ Management API errors when they occur (e.g. invalid requests).
What changes were made?
The important change is to
client.go
. I extracted the existing parsing logic into a new method calledparseResponseErrors
, and call this fromexecuteRequest
, which every API call ultimately uses.What does this change?
For
GET
requests, nothing changes. However, forPUT
andDELETE
requests, any error returned from the RabbitMQ Management API will now be returned by rabbithole. This includes404 Not Found
, when trying to delete a resource than does not exist.All this means is that end users should be checking the
err
return value, which is standard practice in go.What else changed?
I updated tests to check the value of the
err
return value. For a small number of tests, this highlighted some flaws, which I fixed. For the majority of tests, nothing changed. This also had the benefit of clearing upGolangCI-Lint
warnings, since those were related to not checking theerr
return value.I also added some clean up to a few tests because I noticed dangling resources (users, exchanges) after all tests had finished running.
Ran
go mod tidy
to prune any no-longer-needed dependencies fromgo.mod
.