Skip to content

Handle HTTP API error responses#25

Merged
yaacov merged 1 commit into
prometheus:masterfrom
tgwizard:handle-http-api-error-responses
Jun 15, 2024
Merged

Handle HTTP API error responses#25
yaacov merged 1 commit into
prometheus:masterfrom
tgwizard:handle-http-api-error-responses

Conversation

@tgwizard

Copy link
Copy Markdown
Contributor

Currently if we query the Prometheus HTTP API with an invalid query, or there are other errors, the run_command or query_range methods just return nil. E.g. for the response

{"status": "error", "error": "1:6: parse error: unexpected identifier \"a\""}

This PR ensures we check the status field in the response body, which should be success on successful responses, and raises RequestError otherwise. Based on https://prometheus.io/docs/prometheus/latest/querying/api/.

I think some way of distinguishing good requests/responses from bad is nice, and given that there's already an exception here, perhaps we can reuse it?

@yaacov

Signed-off-by: Adam Renberg Tamm <adam.renbergtamm@shopify.com>
@tgwizard tgwizard force-pushed the handle-http-api-error-responses branch from 0d5805f to 0dafc9a Compare June 14, 2024 14:18
@yaacov yaacov merged commit a0bee50 into prometheus:master Jun 15, 2024
@yaacov

yaacov commented Jun 15, 2024

Copy link
Copy Markdown
Member

Thanks 💚

@tgwizard tgwizard deleted the handle-http-api-error-responses branch November 15, 2024 10:38
@tgwizard

Copy link
Copy Markdown
Contributor Author

@yaacov would you mind releasing this as v0.6.4?

@yaacov yaacov mentioned this pull request Nov 21, 2024
@yaacov

yaacov commented Nov 21, 2024

Copy link
Copy Markdown
Member

@yaacov would you mind releasing this as v0.6.4?

v0.6.4 released 🎉 🍰

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants