From 590627870aaa4349548bb9bedbc3f4b0bd1f1ef1 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 10 Dec 2024 21:49:03 -0800 Subject: [PATCH] implement some basic status codes for errors --- pkg/service/service.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/service/service.go b/pkg/service/service.go index 6f4950f..7268aa5 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -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(), + }, } }