mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
error: add RespError.CanRetry field (#456)
This commit is contained in:
parent
60742c4b61
commit
4b387c305b
1 changed files with 11 additions and 0 deletions
11
error.go
11
error.go
|
|
@ -142,6 +142,8 @@ type RespError struct {
|
|||
|
||||
StatusCode int
|
||||
ExtraHeader map[string]string
|
||||
|
||||
CanRetry bool
|
||||
}
|
||||
|
||||
func (e *RespError) UnmarshalJSON(data []byte) error {
|
||||
|
|
@ -151,6 +153,7 @@ func (e *RespError) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
e.ErrCode, _ = e.ExtraData["errcode"].(string)
|
||||
e.Err, _ = e.ExtraData["error"].(string)
|
||||
e.CanRetry, _ = e.ExtraData["com.beeper.can_retry"].(bool)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -158,6 +161,9 @@ func (e *RespError) MarshalJSON() ([]byte, error) {
|
|||
data := exmaps.NonNilClone(e.ExtraData)
|
||||
data["errcode"] = e.ErrCode
|
||||
data["error"] = e.Err
|
||||
if e.CanRetry {
|
||||
data["com.beeper.can_retry"] = e.CanRetry
|
||||
}
|
||||
return json.Marshal(data)
|
||||
}
|
||||
|
||||
|
|
@ -188,6 +194,11 @@ func (e RespError) WithStatus(status int) RespError {
|
|||
return e
|
||||
}
|
||||
|
||||
func (e RespError) WithCanRetry(canRetry bool) RespError {
|
||||
e.CanRetry = canRetry
|
||||
return e
|
||||
}
|
||||
|
||||
func (e RespError) WithExtraData(extraData map[string]any) RespError {
|
||||
e.ExtraData = exmaps.NonNilClone(e.ExtraData)
|
||||
maps.Copy(e.ExtraData, extraData)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue