Return a more useful error?

This commit is contained in:
Neil Alexander 2022-10-05 16:46:28 +01:00
parent 201f363d30
commit 9437126bd8
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 8 additions and 1 deletions

View file

@ -57,6 +57,11 @@ func (p *PerformError) JSONResponse() util.JSONResponse {
// TODO: Should we assert this is in fact JSON? E.g gjson parse?
JSON: json.RawMessage(p.Msg),
}
case PerformErrorNotFound:
return util.JSONResponse{
Code: http.StatusNotFound,
JSON: jsonerror.NotFound(p.Msg),
}
default:
return util.ErrorResponse(p)
}
@ -73,6 +78,8 @@ const (
PerformErrorNoOperation PerformErrorCode = 4
// PerformErrRemote means that the request failed and the PerformError.Msg is the raw remote JSON error response
PerformErrRemote PerformErrorCode = 5
// PerformErrorNotFound means the thing they were trying to do was not found.
PerformErrorNotFound PerformErrorCode = 6
)
type PerformJoinRequest struct {

View file

@ -92,7 +92,7 @@ func (r *Inviter) PerformInvite(
}
if userRes.Available {
res.Error = &api.PerformError{
Code: api.PerformErrorBadRequest,
Code: api.PerformErrorNotFound,
Msg: fmt.Sprintf("The user ID %q does not exist!", targetUserID),
}
return nil, nil