MCPcopy
hub / github.com/devtron-labs/devtron / ParseK8sClientErrorToApiError

Function ParseK8sClientErrorToApiError

pkg/k8s/helper.go:48–64  ·  view source on GitHub ↗
(err error)

Source from the content-addressed store, hash-verified

46}
47
48func ParseK8sClientErrorToApiError(err error) *util.ApiError {
49 if apiErr := (&util.ApiError{}); errors.As(err, &apiErr) {
50 // do not change the error if it is already an ApiError
51 return apiErr
52 }
53 // if error is of type k8sErrors.APIStatus, then extract the message from it
54 if status, ok := err.(k8sErrors.APIStatus); ok || errors.As(err, &status) {
55 return util.DefaultApiError().
56 WithHttpStatusCode(int(status.Status().Code)).
57 WithUserDetailMessage(status.Status().Message).
58 WithInternalMessage(status.Status().Message)
59 }
60 // generic error
61 return util.DefaultApiError().
62 WithUserDetailMessage(err.Error()).
63 WithInternalMessage(err.Error())
64}
65
66// StripPrereleaseFromK8sVersion takes in k8sVersion and stripe pre-release from semver version and return sanitized k8sVersion
67// or error if invalid version provided, e.g. if k8sVersion = "1.25.16-eks-b9c9ed7", then it returns "1.25.16".

Callers 1

Calls 6

DefaultApiErrorFunction · 0.92
WithInternalMessageMethod · 0.80
WithUserDetailMessageMethod · 0.80
WithHttpStatusCodeMethod · 0.80
StatusMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…