Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

introduce new PriceEstimationError #1188

Merged
merged 6 commits into from
Oct 4, 2021
Merged

Conversation

bh2smith
Copy link
Contributor

@bh2smith bh2smith commented Oct 4, 2021

While working on the new Fee & Quote endpoint, I noticed that our markets endpoint was returning an internal server error on something that would have been "BAD REQUEST"

Particularly,

https://protocol-mainnet.gnosis.io/api/v1/markets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48-0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/buy/0

and

https://protocol-mainnet.gnosis.io/api/v1/markets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48-0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/sell/0

Which should fail with a ZeroAmount error.

Test Plan

No logic changes, existing CI.

@bh2smith bh2smith requested a review from a team October 4, 2021 10:29
@vkgnosis
Copy link
Contributor

vkgnosis commented Oct 4, 2021

I'm not a fan of having this logic be in shared and on the price estimation trait. Price estimation is specialized component that shouldn't care about about requests are handled, it shouldn't know about warp. If we want to have more code reuse (we don't have to) I'd like that to be a in the api module only.

@bh2smith
Copy link
Contributor Author

bh2smith commented Oct 4, 2021

I'm not a fan of having this logic be in shared and on the price estimation trait.

Totally fair point. The issue I ran into when trying to implement to_warp_reply for this in the correct place was that I wasn't allowed to implement logic outside the module where the struct was declared. Do you have some suggestion on how this can be more appropriately done?

@vkgnosis
Copy link
Contributor

vkgnosis commented Oct 4, 2021

You can implement a function price_estimation_error_to_warp_reply(error: PriceEstimationError -> ... . You just can't implement it directly on PriceEstimationError. Or you could create a new trait with this function and then impl the trait for the type. The rule is that either the type or the trait have to be in the local crate. For a trait is probably overkill so I'd do the free function.

@nlordell
Copy link
Contributor

nlordell commented Oct 4, 2021

Another option is to implement From:

impl From<PriceEstimationError> for Error<'static> {
    // ...
}

I'm also a fan of just a floating function in this case (I think trait might be a tad overkill here).

@bh2smith
Copy link
Contributor Author

bh2smith commented Oct 4, 2021

Cool folks thank for the comments. I will go with the free floating function (for now). One the bigger PR has the trait, I can adjust it then.

@bh2smith
Copy link
Contributor Author

bh2smith commented Oct 4, 2021

Fixed this - now includes only relevant changes to the Missing Price Estimation Error.

@codecov-commenter
Copy link

codecov-commenter commented Oct 4, 2021

Codecov Report

Merging #1188 (4b9adb4) into main (e0e077d) will increase coverage by 0.10%.
The diff coverage is 14.28%.

@@            Coverage Diff             @@
##             main    #1188      +/-   ##
==========================================
+ Coverage   67.15%   67.26%   +0.10%     
==========================================
  Files         135      135              
  Lines       27210    27189      -21     
==========================================
+ Hits        18273    18288      +15     
+ Misses       8937     8901      -36     

@@ -77,6 +77,7 @@ impl From<PriceEstimationError> for Error {
match other {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe Error type should be:

enum Error {
    SellAmountDoesNotCoverFee,
    PriceEstimate(PriceEstimationError),
}

This would avoid duplicated error messages as well as error variants.

Copy link
Contributor

@nlordell nlordell left a comment

Choose a reason for hiding this comment

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

Looks good. Tiny nit.

@bh2smith bh2smith merged commit 07e3829 into main Oct 4, 2021
@bh2smith bh2smith deleted the refactor-price-estimation-error branch October 4, 2021 17:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants