implement some basic status codes for errors

This commit is contained in:
Quaternions 2024-12-10 21:49:03 -08:00
parent ca5c67cb4b
commit 590627870a

View File

@ -24,8 +24,18 @@ type Service struct {
//
// Used for common default response.
func (svc *Service) NewError(ctx context.Context, err error) *api.ErrorStatusCode {
status := 500
if errors.Is(err,ErrPermissionDenied){
status = 403
}
if errors.Is(err,ErrUserInfo){
status = 401
}
return &api.ErrorStatusCode{
StatusCode: 500,
Response: api.Error{Message: err.Error()},
StatusCode: status,
Response: api.Error{
Code: int64(status),
Message: err.Error(),
},
}
}