You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-58Lines changed: 18 additions & 58 deletions
Original file line number
Diff line number
Diff line change
@@ -8,75 +8,35 @@ Sending any error back to the user can pose a [big security risk](https://owasp.
8
8
For this reason we developed an error registry that allows you to register specific error handlers
9
9
for your application. This way you can control what information is sent back to the user.
10
10
11
-
You can register errors in 3 ways:
12
-
- By error type
13
-
- By value of string errors
14
-
- By defining the error name yourself
15
-
16
-
## 👷 V2 migration guide
17
-
18
-
V2 of this library changes the interface of all the methods to allow contexts to be passed to handlers. This
19
-
allows you to add additional data to the final response.
20
-
21
-
The interface changes are as follows.
22
-
23
-
-`RegisterErrorHandler` and all its variants take a context as a first parameter in the handler, allowing you to pass more data to the response
24
-
-`RegisterErrorHandler` and all its variants require the callback function to return `(int, any)` instead of `(int, R)`, removing the unnecessary generic
25
-
- Both `NewErrorResponse` and `NewErrorResponseFrom` take a context as a first parameter, this could be the request context but that's up to you
11
+
## 👷 V3 migration guide
12
+
13
+
V3 completely revamps the `ErrorRegistry` and now utilises the `errors` package to match errors.
14
+
The following changes have been made:
15
+
16
+
-`RegisterErrorHandler` now requires a concrete instance of the error as its first argument
17
+
-`RegisterErrorHandlerOn` now requires a concrete instance of the error as its second argument
18
+
-`RegisterStringErrorHandler` has been removed, use static `errors.New` in `RegisterErrorHandler`to get this to work
19
+
-`RegisterStringErrorHandlerOn` has been removed, use static `errors.New` in `RegisterErrorHandlerOn`to get this to work
20
+
-`RegisterCustomErrorTypeHandler` has been removed, wrap unexported errors from libraries to create handlers for these
21
+
-`RegisterCustomErrorTypeHandlerOn` has been removed, wrap unexported errors from libraries to create handlers for these
22
+
-`ErrorRegistry` changes:
23
+
-`DefaultCode` has been removed, use `RegisterDefaultHandler` instead
24
+
-`DefaultResponse` has been removed, use `RegisterDefaultHandler` instead
25
+
-`SetDefaultResponse` has been removed, use `RegisterDefaultHandler` instead
26
26
27
27
## ⬇️ Installation
28
28
29
-
`go get github.com/ing-bank/ginerr/v2`
29
+
`go get github.com/ing-bank/ginerr/v3`
30
30
31
31
## 📋 Usage
32
32
33
-
```go
34
-
package main
35
-
36
-
import (
37
-
"github.com/gin-gonic/gin"
38
-
"github.com/ing-bank/ginerr/v2"
39
-
"net/http"
40
-
)
41
-
42
-
typeMyErrorstruct {
43
-
}
44
-
45
-
func(m *MyError) Error() string {
46
-
return"Something went wrong!"
47
-
}
48
-
49
-
// Response is an example response object, you can return anything you like
0 commit comments