Skip to content

Commit

Permalink
Merge pull request #97 from Concordium/better-errors
Browse files Browse the repository at this point in the history
Don't reconnect on request failures.
  • Loading branch information
abizjak authored Oct 19, 2023
2 parents a4fcc0b + 5ed4808 commit 13d691f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Unreleased changes

## 0.29.1

- Improve reconnect handling. If the request to the node times out or fails due
to resource exhaustion then the connection to the node is longer reset.

## 0.29.0

- Add an optional `success` field to the `transactionStatus` response if
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: wallet-proxy
version: 0.29.0
version: 0.29.1
github: "Concordium/concordium-wallet-proxy"
author: "Concordium"
maintainer: "[email protected]"
Expand Down
16 changes: 14 additions & 2 deletions src/Proxy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import qualified Database.Esqueleto.Legacy as E
import qualified Database.Esqueleto.PostgreSQL.JSON as EJ
import Lens.Micro.Platform hiding ((.=))
import Network.GRPC.HTTP2.Types (GRPCStatusCode (..))
import Network.HTTP.Types (Status, badGateway502, badRequest400, internalServerError500, notFound404)
import Network.HTTP.Types (Status, badGateway502, badRequest400, internalServerError500, notFound404, serviceUnavailable503)
import System.Random
import Text.Read hiding (String)
import Web.Cookie
Expand Down Expand Up @@ -174,7 +174,7 @@ share
total_supply (Ratio Integer)
|]

data ErrorCode = InternalError | RequestInvalid | DataNotFound
data ErrorCode = InternalError | RequestInvalid | DataNotFound | Unavailable
deriving (Eq, Show, Enum)

-- | Configuration for the @appSettings@ endpoint that returns whether the app is
Expand Down Expand Up @@ -446,6 +446,18 @@ runGRPCWithCustomError resp c k = do
StatusNotOk (NOT_FOUND, err) -> do
return $
Left (StatusNotOkError NOT_FOUND, notFound404, DataNotFound, EMGRPCErrorResponse $ "Requested object was not found: " <> err)
-- GRPC response with status code 'CANCELLED', i.e., the server timed out the request.
StatusNotOk (CANCELLED, err) -> do
return $
Left (StatusNotOkError CANCELLED, serviceUnavailable503, Unavailable, EMGRPCErrorResponse $ "The node is overloaded so the request was cancelled: " <> err)
-- GRPC response with status code 'RESOURCE_EXHAUSTED'.
StatusNotOk (RESOURCE_EXHAUSTED, err) -> do
return $
Left (StatusNotOkError RESOURCE_EXHAUSTED, serviceUnavailable503, Unavailable, EMGRPCErrorResponse $ "The node is overloaded so the request was cancelled: " <> err)
-- GRPC response with status code 'DEADLINE_EXCEEDED'
StatusNotOk (DEADLINE_EXCEEDED, err) -> do
return $
Left (StatusNotOkError DEADLINE_EXCEEDED, serviceUnavailable503, Unavailable, EMGRPCErrorResponse $ "The node is overloaded so the request was cancelled: " <> err)
-- GRPC response with valid non-'OK' status code.
StatusNotOk (status, err) -> do
$(logError) $ "Got non-OK GRPC status code '" <> Text.pack (show status) <> "': " <> Text.pack err
Expand Down
2 changes: 1 addition & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extra-deps:
commit: 4e9058db74e7a27dee0c92c4a754086e8a45a592

- github: Concordium/http2-grpc-haskell
commit: a4a0a31d44f754bf61868552ee5b256d94eed4de
commit: e52874ac2923f5177696e6dd4251fdb0f7dda87b
subdirs:
- http2-client-grpc
- http2-grpc-proto-lens
Expand Down

0 comments on commit 13d691f

Please sign in to comment.