MCPcopy
hub / github.com/pocketbase/pocketbase / resolveSafeErrorItem

Function resolveSafeErrorItem

tools/router/error.go:206–231  ·  view source on GitHub ↗

resolveSafeErrorItem extracts from each validation error its public safe error code and message.

(err any)

Source from the content-addressed store, hash-verified

204// resolveSafeErrorItem extracts from each validation error its
205// public safe error code and message.
206func resolveSafeErrorItem(err any) any {
207 data := map[string]any{}
208
209 if obj, ok := err.(SafeErrorItem); ok {
210 // extract the specific error code and message
211 data["code"] = obj.Code()
212 data["message"] = inflector.Sentenize(obj.Error())
213 } else {
214 // fallback to the default public safe values
215 data["code"] = "validation_invalid_value"
216 data["message"] = "Invalid value."
217 }
218
219 if s, ok := err.(SafeErrorParamsResolver); ok {
220 params := s.Params()
221 if len(params) > 0 {
222 data["params"] = params
223 }
224 }
225
226 if s, ok := err.(SafeErrorResolver); ok {
227 return s.Resolve(data)
228 }
229
230 return data
231}

Callers 1

resolveSafeErrorsDataFunction · 0.85

Calls 5

SentenizeFunction · 0.92
ParamsMethod · 0.80
CodeMethod · 0.65
ErrorMethod · 0.65
ResolveMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…