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)
| 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] |
| 180 | func 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 | |
| 197 | func 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) |
searching dependent graphs…