Skip to content

Commit 368eee0

Browse files
author
Anders Qvist
committed
Update README error handler example.
1 parent ffdc4de commit 368eee0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,11 +319,24 @@ oidcHandler := oidcgin.New(
319319

320320
### Custom error handler
321321

322-
It is possible to add a custom function to handle errors. It will not be possible to change anything using it, but you will be able to add logic for logging as an example.
322+
It is possible to add a custom function to handle errors. The error handler can return an `options.Response` which will be rendered by the middleware. Returning `nil` will result in a default 400/401 error.
323323

324324
```go
325-
errorHandler := func(description options.ErrorDescription, err error) {
326-
fmt.Printf("Description: %s\tError: %v\n", description, err)
325+
type Message struct {
326+
Message string `json:"message"`
327+
Url string `json:"url"`
328+
}
329+
330+
errorHandler := func(ctx context.Context, request *OidcError) *Response {
331+
message := Message {
332+
Message: request.status,
333+
Url: request.Url,
334+
}
335+
json, _ := json.Marshal(message)
336+
return &options.Response {
337+
Status: 418,
338+
Body: json,
339+
}
327340
}
328341

329342
oidcHandler := oidcgin.New(

0 commit comments

Comments
 (0)