Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revise API error codes #2293

Merged
merged 3 commits into from
Nov 5, 2020
Merged

Revise API error codes #2293

merged 3 commits into from
Nov 5, 2020

Conversation

piotr-iohk
Copy link
Contributor

Issue Number

ADP-291

Overview

  • f533091
    Revise error codes: - 404 when wallet not found - 403 when transaction is too big

  • 430a31f
    Update swagger

  • e90b264
    Update integration tests

Comments

Whie reviewing #2258 I noticed that some error codes are a bit inconsistent, e.g.:

  • 410 or 404 is returned when the wallet is not found.
  • 400 or 403 - when transaction is too big.

This pr is about to revise it and:

  • return 404 on wallet not found (removing 410 altogether)
  • return 403 on transaction too big

@piotr-iohk piotr-iohk requested review from hasufell and KtorZ November 4, 2020 11:10
@piotr-iohk piotr-iohk self-assigned this Nov 4, 2020
@piotr-iohk piotr-iohk added the RESOLVING ISSUE Mark a PR as resolving issues, for auto-generated CHANGELOG label Nov 4, 2020
Copy link
Contributor

@hasufell hasufell left a comment

Choose a reason for hiding this comment

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

Did you consider dropping 415 altogether?

@@ -2411,7 +2410,7 @@ instance Buildable e => LiftHandler (ErrSelectForPayment e) where
, "transaction, then cancel the previous one first."
]
ErrSelectForPaymentTxTooLarge maxSize maxN ->
apiError err400 TransactionIsTooBig $ mconcat
apiError err403 TransactionIsTooBig $ mconcat
Copy link
Contributor

@hasufell hasufell Nov 4, 2020

Choose a reason for hiding this comment

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

Not sure, I think this might actually be https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/413

Copy link
Member

Choose a reason for hiding this comment

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

Sounds relevant for this use case indeed.

Copy link
Contributor Author

@piotr-iohk piotr-iohk Nov 4, 2020

Choose a reason for hiding this comment

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

Judging by the error message I'd say yes and no.

Yes, in case where the metadata is too big. As error message suggests:

Alternatively, try sending to less recipients or with smaller metadata.

Not necessarily, if the transaction turns out to be too big:

Note that I am selecting inputs randomly, so retrying *may work* 

For the sake of keeping it simple I'd stay with 403, which is more general.

@@ -2440,8 +2439,8 @@ instance LiftHandler ErrSignPayment where
handler = \case
ErrSignPaymentMkTx e -> handler e
ErrSignPaymentNoSuchWallet e -> (handler e)
{ errHTTPCode = 410
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, so Gone would be a viable option if we know the wallet existed beforehand. But I guess we don't?

Copy link
Contributor

Choose a reason for hiding this comment

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

So, all uses of this type are as follows

    withRootKey @_ @s ctx wid pwd ErrSignPaymentWithRootKey $ \xprv scheme -> do
        let pwdP = preparePassphrase scheme pwd
        mapExceptT atomically $ do
            cp <- withExceptT ErrSignPaymentNoSuchWallet $ withNoSuchWallet wid $
                readCheckpoint (PrimaryKey wid)
            (cs', s') <- assignChangeAddressesForSelection
                argGenChange cs (getState cp)
            withExceptT ErrSignPaymentNoSuchWallet $
                putCheckpoint (PrimaryKey wid) (updateState s' cp)

            let keyFrom = isOwned (getState cp) (xprv, pwdP)
            let rewardAcnt = mkRewardAccount (xprv, pwdP)

            (tx, sealedTx) <- withExceptT ErrSignPaymentMkTx $ ExceptT $
                pure $ mkStdTx tl rewardAcnt keyFrom txExp md cs'

            (time, meta) <- liftIO $ mkTxMeta ti (currentTip cp) s' tx cs' txExp
            return (tx, meta, time, sealedTx)

That means we can only hit this code-path if we found a root key for the given wallet id. Does that imply the wallet existed?

Copy link
Member

Choose a reason for hiding this comment

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

Gone made sense in the context of concurrent request. When one creates a transaction, there are multiple back-and-forth with the database in separate db transactions. In principle, the wallet could disappear between any of these db transaction might there be a concurrent request deleting the wallet at the same time.

Arguably, this is veeeeeeeery edgy, and from a user perspective doesn't matter much. So changing to 404 sounds like a good move.

@piotr-iohk
Copy link
Contributor Author

Did you consider dropping 415 altogether?

I haven't actually. As far as I see there are some tests against 415 in the test suite, so maybe let's have it here.

@piotr-iohk
Copy link
Contributor Author

bors r+

@piotr-iohk
Copy link
Contributor Author

bors r-

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 5, 2020

Merge conflict.

Piotr Stachyra added 2 commits November 5, 2020 07:54
 - 404 when wallet not found
 - 403 when transaction is too big
@piotr-iohk piotr-iohk force-pushed the piotr/revise_error_codes branch 2 times, most recently from b84e830 to 6ba09a9 Compare November 5, 2020 07:44
@piotr-iohk piotr-iohk force-pushed the piotr/revise_error_codes branch from 6ba09a9 to 3fe96b3 Compare November 5, 2020 10:02
@piotr-iohk
Copy link
Contributor Author

bors r+

@iohk-bors
Copy link
Contributor

iohk-bors bot commented Nov 5, 2020

Build succeeded:

@iohk-bors iohk-bors bot merged commit 1d9aa32 into master Nov 5, 2020
@iohk-bors iohk-bors bot deleted the piotr/revise_error_codes branch November 5, 2020 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RESOLVING ISSUE Mark a PR as resolving issues, for auto-generated CHANGELOG
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants