MCPcopy
hub / github.com/pocketbase/pocketbase / ToApiError

Function ToApiError

tools/router/error.go:134–147  ·  view source on GitHub ↗

ToApiError wraps err into ApiError instance (if not already).

(err error)

Source from the content-addressed store, hash-verified

132
133// ToApiError wraps err into ApiError instance (if not already).
134func ToApiError(err error) *ApiError {
135 var apiErr *ApiError
136
137 if !errors.As(err, &apiErr) {
138 // no ApiError found -> assign a generic one
139 if errors.Is(err, sql.ErrNoRows) || errors.Is(err, fs.ErrNotExist) {
140 apiErr = NewNotFoundError("", err)
141 } else {
142 apiErr = NewBadRequestError("", err)
143 }
144 }
145
146 return apiErr
147}
148
149// -------------------------------------------------------------------
150

Callers 5

TestToApiErrorFunction · 0.92
TestStaticFunction · 0.92
ProcessMethod · 0.92
ToApiErrorFunction · 0.92
ErrorHandlerFunction · 0.70

Calls 3

IsMethod · 0.80
NewNotFoundErrorFunction · 0.70
NewBadRequestErrorFunction · 0.70

Tested by 2

TestToApiErrorFunction · 0.74
TestStaticFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…