MCPcopy Create free account
hub / github.com/cli/cli / asSearchError

Function asSearchError

pkg/search/searcher.go:322–341  ·  view source on GitHub ↗

asSearchError converts an api.HTTPError into search's own error type, which formats invalid queries differently from the rest of the CLI.

(apiErr api.HTTPError)

Source from the content-addressed store, hash-verified

320// asSearchError converts an api.HTTPError into search's own error type, which formats
321// invalid queries differently from the rest of the CLI.
322func asSearchError(apiErr api.HTTPError) error {
323 searchErr := httpError{
324 Message: apiErr.Message,
325 RequestURL: apiErr.RequestURL,
326 StatusCode: apiErr.StatusCode,
327 }
328 // A non-JSON response leaves Message empty, where this package used to report the status line.
329 if searchErr.Message == "" {
330 searchErr.Message = fmt.Sprintf("%d %s", apiErr.StatusCode, http.StatusText(apiErr.StatusCode))
331 }
332 for _, item := range apiErr.Errors {
333 searchErr.Errors = append(searchErr.Errors, httpErrorItem{
334 Code: item.Code,
335 Field: item.Field,
336 Message: item.Message,
337 Resource: item.Resource,
338 })
339 }
340 return searchErr
341}
342
343// nextPage extracts the next page number from an API response's link header. if
344// the provided link header is empty or there is no next page, zero is returned.

Callers 1

searchMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected