2022-02-07 20:36:09 +00:00
|
|
|
# Copyright (c) 2018-2022 Status Research & Development GmbH
|
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2022-07-29 10:53:42 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2022-02-07 20:36:09 +00:00
|
|
|
|
|
|
|
import
|
2022-10-24 20:32:52 +00:00
|
|
|
chronos, presto/client,
|
2022-02-07 20:36:09 +00:00
|
|
|
"."/[rest_types, eth2_rest_serialization]
|
|
|
|
|
|
|
|
export chronos, client, rest_types, eth2_rest_serialization
|
|
|
|
|
|
|
|
proc raiseGenericError*(resp: RestPlainResponse) {.
|
|
|
|
noreturn, raises: [RestError, Defect].} =
|
|
|
|
let error =
|
|
|
|
block:
|
2022-09-29 20:55:18 +00:00
|
|
|
let res = decodeBytes(RestErrorMessage, resp.data, resp.contentType)
|
2022-02-07 20:36:09 +00:00
|
|
|
if res.isErr():
|
|
|
|
let msg = "Incorrect response error format (" & $resp.status &
|
|
|
|
") [" & $res.error() & "]"
|
|
|
|
raise newException(RestError, msg)
|
|
|
|
res.get()
|
|
|
|
let msg = "Error response (" & $resp.status & ") [" & error.message & "]"
|
|
|
|
raise newException(RestError, msg)
|
|
|
|
|
|
|
|
proc raiseUnknownStatusError*(resp: RestPlainResponse) {.
|
|
|
|
noreturn, raises: [RestError, Defect].} =
|
|
|
|
let msg = "Unknown response status error (" & $resp.status & ")"
|
|
|
|
raise newException(RestError, msg)
|