The ErrorResponse exception now preserves information about the HTTP status code and reason

This commit is contained in:
Zahary Karadjov 2023-03-01 12:40:16 +02:00
parent 38950a786d
commit 07e4705b1f
No known key found for this signature in database
GPG Key ID: C1F42EAFF38D570F
2 changed files with 2 additions and 1 deletions

View File

@ -99,7 +99,7 @@ method call*(client: RpcHttpClient, name: string,
if res.status < 200 or res.status >= 300: # res.status is not 2xx (success)
closeRefs()
raise newException(ErrorResponse, "POST Response: " & $res.status)
raise (ref ErrorResponse)(status: res.status, msg: res.reason)
debug "Message sent to RPC server",
address = client.httpAddress, msg_len = len(reqBody)

View File

@ -3,6 +3,7 @@ type
## Base type of all nim-json-rpc errors
ErrorResponse* = object of JsonRpcError
status*: int
## raised when the server responded with an error
InvalidResponse* = object of JsonRpcError