-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use APIError #132
Comments
Do you mean anything special by APIError? Any libraries or interfaces? |
I could imagine using something like this when returning errors // APIError holds message and statusCode for api errors
type APIError struct {
Code int `json:"code"`
Message string `json:"message"`
Detail string `json:"detail,omitempty"`
}
// Error stringifies the APIError
func (apiError APIError) Error() string {
return "Code: " + strconv.Itoa(apiError.Code) + "Message: " + apiError.Message + "Detail: " + apiError.Detail
} |
When improving the error handling, we could also use error wrapping. In order to provide better errors, that are way more helpful when searching for problems. My favorite package for error wrapping is: I stole the error wrapping stuff from dave cheney and i'm using it everywhere. Makes life easier. |
I was actually just referring to the https://github.com/Nerzal/gocloak/blob/master/models.go#L58 Error wrapping is also now standard library as of go 1.13. Not sure if you want to make that a requirement though. |
@SVilgelm what do you think? Optional (Additionaly): |
wrapping errors means adding additional restrictions of go 1.13, am I right? |
we don't have to restrict to go 1.13 if we use the pkg/errors lib for that. |
Ok, let's do it :) |
i'll do that. shouldn't take long |
Is your feature request related to a problem? Please describe.
It would be nice to get the status code returned from Keycloak.
Describe the solution you'd like
Return APIErrors from gocloak calls. This could be tricky for errors resulting from things other than Keycloak API calls.
Describe alternatives you've considered
Can't think of any though I'm totally open to any existing solutions I'm unaware of.
Additional context
I have my own HTTP service in front of gocloak and right now it's hard to determine what errors and response codes I should return. For example I might get an error back like this "400 Bad Request: Password policy not met. See logs for details".
I'd like to be able to set my response code to 400 and set an appropriate error of "Password policy not met." The "See logs for details" part doesn't really make sense but I'm not sure there is anything that can be done to solve that.
The text was updated successfully, but these errors were encountered: