mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Handle network errors better when returning remote HTTP errors
This commit is contained in:
parent
f3d9bf0670
commit
3cc40408fc
|
|
@ -90,7 +90,6 @@ func (r *FederationSenderInternalAPI) PerformJoin(
|
|||
// If we reach here then we didn't complete a join for some reason.
|
||||
var httpErr gomatrix.HTTPError
|
||||
if ok := errors.As(lastErr, &httpErr); ok {
|
||||
logrus.Infof("TYPE CAST LASTERR OK!")
|
||||
httpErr.Message = string(httpErr.Contents)
|
||||
response.LastError = &httpErr
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ func (h *httpFederationSenderInternalAPI) PerformJoin(
|
|||
if err != nil {
|
||||
response.LastError = &gomatrix.HTTPError{
|
||||
Message: err.Error(),
|
||||
Code: 599, // to distinguish from genuine 500
|
||||
Code: 0,
|
||||
WrappedError: err,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,12 +46,13 @@ func (p *PerformError) JSONResponse() util.JSONResponse {
|
|||
JSON: jsonerror.Forbidden(p.Msg),
|
||||
}
|
||||
case PerformErrRemote:
|
||||
code := p.RemoteCode
|
||||
if code == 0 {
|
||||
code = 500
|
||||
// if the code is 0 then something bad happened and it isn't
|
||||
// a remote HTTP error being encapsulated, e.g network error to remote.
|
||||
if p.RemoteCode == 0 {
|
||||
return util.ErrorResponse(fmt.Errorf("%s", p.Msg))
|
||||
}
|
||||
return util.JSONResponse{
|
||||
Code: code,
|
||||
Code: p.RemoteCode,
|
||||
// TODO: Should we assert this is in fact JSON? E.g gjson parse?
|
||||
JSON: json.RawMessage(p.Msg),
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue