MCPcopy Create free account
hub / github.com/brimdata/super / errorResponse

Function errorResponse

service/request.go:303–342  ·  view source on GitHub ↗
(e error)

Source from the content-addressed store, hash-verified

301}
302
303func errorResponse(e error) (status int, ae *api.Error) {
304 status = http.StatusInternalServerError
305 ae = &api.Error{Type: "Error"}
306
307 if list := (srcfiles.ErrorList)(nil); errors.As(e, &list) {
308 ae.CompilationErrors = list
309 }
310
311 var ze *srverr.Error
312 if !errors.As(e, &ze) {
313 ze = &srverr.Error{Err: e}
314 }
315
316 switch {
317 case errors.Is(e, branches.ErrExists) || errors.Is(e, pools.ErrExists):
318 ze.Kind = srverr.Conflict
319 case errors.Is(e, branches.ErrNotFound) || errors.Is(e, commits.ErrNotFound) ||
320 errors.Is(e, pools.ErrNotFound) || errors.Is(e, fs.ErrNotExist):
321 ze.Kind = srverr.NotFound
322 }
323
324 switch ze.Kind {
325 case srverr.Invalid:
326 status = http.StatusBadRequest
327 case srverr.NotFound:
328 status = http.StatusNotFound
329 case srverr.Exists:
330 status = http.StatusBadRequest
331 case srverr.Conflict:
332 status = http.StatusConflict
333 case srverr.NoCredentials:
334 status = http.StatusUnauthorized
335 case srverr.Forbidden:
336 status = http.StatusForbidden
337 }
338
339 ae.Kind = ze.Kind.String()
340 ae.Message = ze.Message()
341 return
342}

Callers 1

ErrorMethod · 0.85

Calls 3

MessageMethod · 0.95
IsMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected