rust-payjoin icon indicating copy to clipboard operation
rust-payjoin copied to clipboard

Move shared response processing code to ohttp.rs

Open spacebear21 opened this issue 8 months ago • 2 comments

The process_res methods across send and receive have a lot of shared code that can be extracted into reusable functions. process_get_res and process_post_res essentially do the same thing, and could conceivably be combined into one function. They were kept separate because "202 Accepted" is not a valid response for POST requests.

spacebear21 avatar Apr 18 '25 01:04 spacebear21

Leaving in draft for now because some follow-up items need to be addressed:

  • process_response methods return inconsistent error types when POSTing vs. GETting, specifically: EncapsulationError vs. ResponseError for send and SessionError vs. Error for receive.
  • There are four duplicated variants between InternalEncapsulationError and InternalSessionError.
    • Also, EncapsulationError is a misnomer since it afaict it's exclusively raised when decapsulating responses.
    • The Hpke variant has nothing to do with en/decapsulation.

spacebear21 avatar Apr 18 '25 01:04 spacebear21

Pull Request Test Coverage Report for Build 15500115610

Details

  • 51 of 75 (68.0%) changed or added relevant lines in 5 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 85.043%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin/src/receive/v2/error.rs 0 2 0.0%
payjoin/src/send/v2/error.rs 0 3 0.0%
payjoin/src/ohttp.rs 28 47 59.57%
<!-- Total: 51 75
Totals Coverage Status
Change from base Build 15449709719: -0.01%
Covered Lines: 6772
Relevant Lines: 7963

💛 - Coveralls

coveralls avatar Apr 18 '25 01:04 coveralls

are there other from conversions that can be deleted?

DanGould avatar Jun 06 '25 17:06 DanGould

The error audit I mentioned in my other comment can be addressed later in a follow-up, I'll make a new issue.

are there other from conversions that can be deleted?

I had a second commit locally that I hadn't pushed which simplifies the From mappings. The PR is still a net addition but I think the simplification is significant.

spacebear21 avatar Jun 06 '25 18:06 spacebear21

The latest push fixes process_get_res and replaces the From implementations with map_err.

spacebear21 avatar Jun 06 '25 19:06 spacebear21

ec4b67e7f39ee8e707c7a272b7459fb836ae0a50 only applies your suggestions re: response.status().

spacebear21 avatar Jun 06 '25 21:06 spacebear21