MCPcopy Create free account
hub / github.com/daodst/chat / JSONResponse

Method JSONResponse

roomserver/api/perform.go:26–62  ·  view source on GitHub ↗

JSONResponse maps error codes to suitable HTTP error codes, defaulting to 500.

()

Source from the content-addressed store, hash-verified

24
25// JSONResponse maps error codes to suitable HTTP error codes, defaulting to 500.
26func (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
64const (
65 // PerformErrorNotAllowed means the user is not allowed to invite/join/etc this room (e.g join_rule:invite or banned)

Callers 12

JoinRoomByIDOrAliasFunction · 0.80
SetVisibilityFunction · 0.80
createRoomFunction · 0.80
AdminEvacuateRoomFunction · 0.80
AdminEvacuateUserFunction · 0.80
PeekRoomByIDOrAliasFunction · 0.80
UnpeekRoomByIDFunction · 0.80
sendInviteFunction · 0.80
SendInviteAsRoomOwnerFunction · 0.80
processInviteFunction · 0.80
SendOwnerInviteFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected