MCPcopy
hub / github.com/harness/harness / Translate

Function Translate

app/api/usererror/translate.go:36–152  ·  view source on GitHub ↗
(ctx context.Context, err error)

Source from the content-addressed store, hash-verified

34)
35
36func Translate(ctx context.Context, err error) *Error {
37 var (
38 rError *Error
39 checkError *check.ValidationError
40 appError *errors.Error
41 unrelatedHistoriesErr *api.UnrelatedHistoriesError
42 maxBytesErr *http.MaxBytesError
43 codeOwnersTooLargeError *codeowners.TooLargeError
44 codeOwnersFileParseError *codeowners.FileParseError
45 lockError *lock.Error
46 )
47
48 // print original error for debugging purposes
49 log.Ctx(ctx).Info().Err(err).Msgf("translating error to user facing error")
50
51 // TODO: Improve performance of checking multiple errors with errors.Is
52
53 switch {
54 // api errors
55 case errors.As(err, &rError):
56 return rError
57
58 // api auth errors
59 case errors.Is(err, apiauth.ErrForbidden):
60 return ErrForbidden
61
62 case errors.Is(err, apiauth.ErrUnauthorized):
63 return ErrUnauthorized
64
65 // validation errors
66 case errors.As(err, &checkError):
67 return New(http.StatusBadRequest, checkError.Error())
68
69 // store errors
70 case errors.Is(err, store.ErrResourceNotFound):
71 return ErrNotFound
72 case errors.Is(err, store.ErrDuplicate):
73 return ErrDuplicate
74 case errors.Is(err, store.ErrPrimaryPathCantBeDeleted):
75 return ErrPrimaryPathCantBeDeleted
76 case errors.Is(err, store.ErrPathTooLong):
77 return ErrPathTooLong
78 case errors.Is(err, store.ErrNoChangeInRequestedMove):
79 return ErrNoChange
80 case errors.Is(err, store.ErrIllegalMoveCyclicHierarchy):
81 return ErrCyclicHierarchy
82 case errors.Is(err, store.ErrSpaceWithChildsCantBeDeleted):
83 return ErrSpaceWithChildsCantBeDeleted
84 case errors.Is(err, limiter.ErrMaxNumReposReached):
85 return Forbidden(err.Error())
86
87 // upload errors
88 case errors.Is(err, blob.ErrNotFound):
89 return ErrNotFound
90 case errors.As(err, &maxBytesErr):
91 return RequestTooLargef("The request is too large. maximum allowed size is %d bytes", maxBytesErr.Limit)
92
93 case errors.Is(err, store.ErrLicenseExpired):

Callers 2

TranslatedUserErrorFunction · 0.92
pktErrorFunction · 0.92

Calls 15

AsFunction · 0.92
IsFunction · 0.92
RequestTooLargefFunction · 0.85
NewWithPayloadFunction · 0.85
httpStatusCodeFunction · 0.85
UnprocessableEntityFunction · 0.85
errorFromLockErrorFunction · 0.85
MsgfMethod · 0.80
NewFunction · 0.70
ForbiddenFunction · 0.70
BadRequestfFunction · 0.70
ErrMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…