MCPcopy
hub / github.com/zitadel/oidc / WriteError

Function WriteError

pkg/op/error.go:180–195  ·  view source on GitHub ↗

WriteError asserts for a [StatusError] containing an [oidc.Error]. If no `StatusError` is found, the status code will default to [http.StatusBadRequest]. If no `oidc.Error` was found in the parent, the error type defaults to [oidc.ServerError]. When there was no `StatusError` and the `oidc.Error` is

(w http.ResponseWriter, r *http.Request, err error, logger *slog.Logger)

Source from the content-addressed store, hash-verified

178// When there was no `StatusError` and the `oidc.Error` is of type `oidc.ServerError`,
179// the status code will be set to [http.StatusInternalServerError]
180func WriteError(w http.ResponseWriter, r *http.Request, err error, logger *slog.Logger) {
181 var statusError StatusError
182 if errors.As(err, &statusError) {
183 writeError(w, r,
184 oidc.DefaultToServerError(statusError.parent, statusError.parent.Error()),
185 statusError.statusCode, logger,
186 )
187 return
188 }
189 statusCode := http.StatusBadRequest
190 e := oidc.DefaultToServerError(err, err.Error())
191 if e.ErrorType == oidc.ServerError {
192 statusCode = http.StatusInternalServerError
193 }
194 writeError(w, r, e, statusCode, logger)
195}
196
197func writeError(w http.ResponseWriter, r *http.Request, err *oidc.Error, statusCode int, logger *slog.Logger) {
198 logger.Log(r.Context(), err.LogLevel(), "request error", "oidc_error", err, "status_code", statusCode)

Callers 15

TestWriteErrorFunction · 0.85
withClientMethod · 0.85
authorizeHandlerMethod · 0.85
tokensHandlerMethod · 0.85
jwtProfileHandlerMethod · 0.85
codeExchangeHandlerMethod · 0.85
refreshTokenHandlerMethod · 0.85
tokenExchangeHandlerMethod · 0.85
deviceTokenHandlerMethod · 0.85
introspectionHandlerMethod · 0.85

Calls 3

DefaultToServerErrorFunction · 0.92
writeErrorFunction · 0.85
ErrorMethod · 0.45

Tested by 1

TestWriteErrorFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…