mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 16:30:17 +02:00
zero: only leave public packages in pkg/zero (#4854)
This commit is contained in:
parent
a6ae9d3f2d
commit
b66634d1e6
24 changed files with 22 additions and 22 deletions
42
internal/zero/apierror/request_id.go
Normal file
42
internal/zero/apierror/request_id.go
Normal file
|
@ -0,0 +1,42 @@
|
|||
package apierror
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// RequestIDError is an error that wraps another error and includes the response ID
|
||||
type RequestIDError struct {
|
||||
Err error
|
||||
ResponseID *string
|
||||
}
|
||||
|
||||
// Error implements error for RequestIDError
|
||||
func (e *RequestIDError) Error() string {
|
||||
if e.ResponseID == nil {
|
||||
return e.Err.Error()
|
||||
}
|
||||
return fmt.Sprintf("[x-response-id:%s]: %v", *e.ResponseID, e.Err)
|
||||
}
|
||||
|
||||
// Unwrap implements errors.Unwrap for RequestIDError
|
||||
func (e *RequestIDError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
// Is implements errors.Is for RequestIDError
|
||||
func (e *RequestIDError) Is(err error) bool {
|
||||
//nolint:errorlint
|
||||
_, ok := err.(*RequestIDError)
|
||||
return ok
|
||||
}
|
||||
|
||||
// WithRequestID creates a new RequestIDError
|
||||
func WithRequestID(err error, headers http.Header) *RequestIDError {
|
||||
r := &RequestIDError{Err: err}
|
||||
id := headers.Get("X-Response-Id")
|
||||
if id != "" {
|
||||
r.ResponseID = &id
|
||||
}
|
||||
return r
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue