-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2258: ADP-291: Document endpoints error codes in the API documentation r=hasufell a=hasufell # Issue Number ADP-291 # Implementation approach This is all best-effort. There are no static checks to ensure we didn't miss anything. There's ongoing work at servant to make this possible: haskell-servant/servant#841 But even that would require a major refactor. Testing all possible errors is also an option, but seems quite excessive. The workflow for figuring out the error codes is roughly: 1. follow the entry point to the the `Handler ()` function e.g. ```hs listTransactions :: forall ctx s t k n. (ctx ~ ApiLayer s t k) => ctx ... -> Handler [ApiTransaction n] ``` 2. check all `liftHandler` calls, which have functions with `ExceptT` as argument, e.g.: ```hs listTransactions :: forall ctx s k t. ( HasDBLayer s k ctx , HasNetworkLayer t ctx ) => ctx ... -> ExceptT ErrListTransactions IO [TransactionInfo] ``` 3. find all the LiftHandler instance, e.g. ```hs instance LiftHandler ErrListTransactions where handler = \case ErrListTransactionsNoSuchWallet e -> handler e ErrListTransactionsStartTimeLaterThanEndTime e -> handler e ErrListTransactionsMinWithdrawalWrong -> apiError err400 MinWithdrawalWrong "The minimum withdrawal value must be at least 1 Lovelace." ErrListTransactionsPastHorizonException e -> handler e ``` 4. follow the recursive handlers to resolve all errors and add client error types to `swagger.yaml`. The error code is the 3rd `ApiErrorCode` argument to `apiError`. 5. Some errors are implicit, e.g. failed parameter parsing etc. These are also in `ApiErrorCode`. Also see the special instance `instance LiftHandler (Request, ServerError)` 6. repeat until exhaustion # Overview - [x] Wallets - [x] Addresses - [x] Coin Selections - [x] Transactions - [x] Migrations - [x] Stake Pools - [x] Utils - [x] Network - [x] Proxy - [x] Settings - [ ] Byron-specific endpoints # Remarks 1. I did not double check the byron endpoints. Many of their endpoints share the same types in `swagger.yaml`, so I assumed they have the same behavior wrt error codes. 2. This will generally be hard to maintain, since yaml anchors aren't enough to express the overlaps of error codes and group them sensibly. It would need something like [dhall](https://github.com/dhall-lang/dhall-lang) to do that. 3. I removed 405 errors, because the HTTP method is part of the very spec. If you follow the spec, you can't get 405. <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: Julian Ospald <julian.ospald@iohk.io> Co-authored-by: KtorZ <matthias.benkort@gmail.com>
- Loading branch information
Showing
6 changed files
with
794 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.