MCPcopy Index your code
hub / github.com/coder/coder / NewJSONErrorResponse

Function NewJSONErrorResponse

aibridge/utils/http.go:18–34  ·  view source on GitHub ↗

NewJSONErrorResponse builds an *http.Response with a JSON body and optional Retry-After header. Used to synthesize bridge-side error responses (e.g. key-pool exhaustion, marshaling fallbacks). Retry-After is set to whole seconds (rounded up) when retryAfter is positive, and omitted otherwise.

(status int, retryAfter time.Duration, body []byte)

Source from the content-addressed store, hash-verified

16// fallbacks). Retry-After is set to whole seconds (rounded up)
17// when retryAfter is positive, and omitted otherwise.
18func NewJSONErrorResponse(status int, retryAfter time.Duration, body []byte) *http.Response {
19 h := http.Header{}
20 h.Set("Content-Type", "application/json")
21 if retryAfter > 0 {
22 h.Set("Retry-After", strconv.Itoa(int(math.Ceil(retryAfter.Seconds()))))
23 }
24 return &http.Response{
25 Status: fmt.Sprintf("%d %s", status, http.StatusText(status)),
26 StatusCode: status,
27 Proto: "HTTP/1.1",
28 ProtoMajor: 1,
29 ProtoMinor: 1,
30 Header: h,
31 Body: io.NopCloser(bytes.NewReader(body)),
32 ContentLength: int64(len(body)),
33 }
34}

Callers 4

TestNewJSONErrorResponseFunction · 0.92
ToResponseMethod · 0.92
ToResponseMethod · 0.92
RoundTripMethod · 0.92

Calls 1

SetMethod · 0.65

Tested by 1

TestNewJSONErrorResponseFunction · 0.74