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