snapshot of https://github.com/go-chi/chi.git (master, 2026-09-15; blobs > 131072B omitted)
Some checks failed
Test / test (1.24.x, ubuntu-latest) (push) Successful in 2m56s
Test / test (1.25.x, ubuntu-latest) (push) Successful in 2m15s
Test / test (1.26.x, ubuntu-latest) (push) Successful in 2m23s
Test / test (1.27.x, ubuntu-latest) (push) Failing after 3m56s
Test / test (1.24.x, windows-latest) (push) Has been cancelled
Test / test (1.25.x, windows-latest) (push) Has been cancelled
Test / test (1.26.x, windows-latest) (push) Has been cancelled
Test / test (1.27.x, windows-latest) (push) Has been cancelled
Some checks failed
Test / test (1.24.x, ubuntu-latest) (push) Successful in 2m56s
Test / test (1.25.x, ubuntu-latest) (push) Successful in 2m15s
Test / test (1.26.x, ubuntu-latest) (push) Successful in 2m23s
Test / test (1.27.x, ubuntu-latest) (push) Failing after 3m56s
Test / test (1.24.x, windows-latest) (push) Has been cancelled
Test / test (1.25.x, windows-latest) (push) Has been cancelled
Test / test (1.26.x, windows-latest) (push) Has been cancelled
Test / test (1.27.x, windows-latest) (push) Has been cancelled
This commit is contained in:
28
_examples/versions/data/errors.go
Normal file
28
_examples/versions/data/errors.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package data
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/render"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrUnauthorized = errors.New("Unauthorized")
|
||||
ErrForbidden = errors.New("Forbidden")
|
||||
ErrNotFound = errors.New("Resource not found")
|
||||
)
|
||||
|
||||
func PresentError(r *http.Request, err error) (*http.Request, interface{}) {
|
||||
switch err {
|
||||
case ErrUnauthorized:
|
||||
render.Status(r, 401)
|
||||
case ErrForbidden:
|
||||
render.Status(r, 403)
|
||||
case ErrNotFound:
|
||||
render.Status(r, 404)
|
||||
default:
|
||||
render.Status(r, 500)
|
||||
}
|
||||
return r, map[string]string{"error": err.Error()}
|
||||
}
|
||||
Reference in New Issue
Block a user