JSONResponse maps error codes to suitable HTTP error codes, defaulting to 500.
()
| 24 | |
| 25 | // JSONResponse maps error codes to suitable HTTP error codes, defaulting to 500. |
| 26 | func (p *PerformError) JSONResponse() util.JSONResponse { |
| 27 | switch p.Code { |
| 28 | case PerformErrorBadRequest: |
| 29 | return util.JSONResponse{ |
| 30 | Code: http.StatusBadRequest, |
| 31 | JSON: jsonerror.Unknown(p.Msg), |
| 32 | } |
| 33 | case PerformErrorNoRoom: |
| 34 | return util.JSONResponse{ |
| 35 | Code: http.StatusNotFound, |
| 36 | JSON: jsonerror.NotFound(p.Msg), |
| 37 | } |
| 38 | case PerformErrorNotAllowed: |
| 39 | return util.JSONResponse{ |
| 40 | Code: http.StatusForbidden, |
| 41 | JSON: jsonerror.Forbidden(p.Msg), |
| 42 | } |
| 43 | case PerformErrorNoOperation: |
| 44 | return util.JSONResponse{ |
| 45 | Code: http.StatusForbidden, |
| 46 | JSON: jsonerror.Forbidden(p.Msg), |
| 47 | } |
| 48 | case PerformErrRemote: |
| 49 | // if the code is 0 then something bad happened and it isn't |
| 50 | // a remote HTTP error being encapsulated, e.g network error to remote. |
| 51 | if p.RemoteCode == 0 { |
| 52 | return util.ErrorResponse(fmt.Errorf("%s", p.Msg)) |
| 53 | } |
| 54 | return util.JSONResponse{ |
| 55 | Code: p.RemoteCode, |
| 56 | // TODO: Should we assert this is in fact JSON? E.g gjson parse? |
| 57 | JSON: json.RawMessage(p.Msg), |
| 58 | } |
| 59 | default: |
| 60 | return util.ErrorResponse(p) |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | const ( |
| 65 | // PerformErrorNotAllowed means the user is not allowed to invite/join/etc this room (e.g join_rule:invite or banned) |
no outgoing calls
no test coverage detected