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

Function httpError

coderd/coderdtest/oidctest/idp.go:1745–1771  ·  view source on GitHub ↗

httpError handles better formatted custom errors.

(rw http.ResponseWriter, defaultCode int, err error)

Source from the content-addressed store, hash-verified

1743
1744// httpError handles better formatted custom errors.
1745func httpError(rw http.ResponseWriter, defaultCode int, err error) {
1746 status := defaultCode
1747
1748 var statusErr statusHookError
1749 if errors.As(err, &statusErr) {
1750 status = statusErr.HTTPStatusCode
1751 }
1752
1753 var oauthErr *oauth2.RetrieveError
1754 if errors.As(err, &oauthErr) {
1755 if oauthErr.Response.StatusCode != 0 {
1756 status = oauthErr.Response.StatusCode
1757 }
1758
1759 rw.Header().Set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
1760 form := url.Values{
1761 "error": {oauthErr.ErrorCode},
1762 "error_description": {oauthErr.ErrorDescription},
1763 "error_uri": {oauthErr.ErrorURI},
1764 }
1765 rw.WriteHeader(status)
1766 _, _ = rw.Write([]byte(form.Encode()))
1767 return
1768 }
1769
1770 http.Error(rw, err.Error(), status)
1771}
1772
1773type fakeRoundTripper struct {
1774 roundTrip func(req *http.Request) (*http.Response, error)

Callers 1

httpHandlerMethod · 0.85

Calls 7

AsMethod · 0.80
EncodeMethod · 0.80
SetMethod · 0.65
WriteMethod · 0.65
HeaderMethod · 0.45
WriteHeaderMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected