Page MenuHomePhabricator

[Chronik] Add `parse_error_status` to parse error msgs as HTTP status
ClosedPublic

Authored by tobias_ruck on Feb 28 2023, 18:30.

Details

Summary

We handle errors using thiserror and eyre, but neither allow us to attach an HTTP status code to the error. We could use a procedual macro (e.g. bitcoinsuite-error-derive), however, this has many downsides.

Instead, we opt for a much simpler approach: Simply encode the HTTP status in the error message as a prefix. This way a DB failure can be prefixed with e.g. "500: ", and when a queried tx is not found in the chain, we can prefix the error with "404: ".

Test Plan

cargo test

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Add missing copyright notice

Fabien added inline comments.
chronik/abc-rust-error/src/http_status.rs
40 ↗(On Diff #38152)

Note to reviewers: the regex is fairly relaxed but StatusCode is very strict and requires the bytes to be in the range 100-999

This revision is now accepted and ready to land.Mar 1 2023, 10:08

rename second status_prefix -> status_bytes