mirror of
https://github.com/vmware-tanzu/pinniped.git
synced 2026-01-07 05:57:02 +00:00
Refactor error handling in authorize endpoint (changes some responses)
- Simplify the error handling in the authorize endpoint by making the private helper functions return fosite-style errors, and having one place that writes those errors to the response. - Some types of errors were previously returned as regular http-style errors. Those have all been converted to be returned as oauth-style errors (which can be redirects to the client), except for http method not found errors. This is a change in behavior from the client's point of view, but only when those unexpected errors happen. These types of errors are more consistent with RFC6749 section 4.1.2.1. - Avoids using the httperr package for error handling. - Create a struct for the handler as a first step toward making smaller functions with fewer parameters.
This commit is contained in:
16
internal/httputil/responseutil/responseutil.go
Normal file
16
internal/httputil/responseutil/responseutil.go
Normal file
@@ -0,0 +1,16 @@
|
||||
// Copyright 2024 the Pinniped contributors. All Rights Reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package responseutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func HTTPErrorf(w http.ResponseWriter, code int, errorFmt string, a ...any) {
|
||||
http.Error(w,
|
||||
fmt.Sprintf("%s: %s", http.StatusText(code), fmt.Sprintf(errorFmt, a...)),
|
||||
code,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user