-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Error handling in MVC mapper functions #1187
Comments
…rror type as a second output value as requested at: #1187
@pantonov , I've just added support for second output of error type for the dynamic dependencies ^ for the upcoming v11.2 . Although you could already do that by: b.Dependencies().Add(func(ctx iris.Context) (v testCustomStruct) {
err := ctx.ReadJSON(&v)
if err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.WriteString(err.Error())
ctx.StopExecution() // this will stop the execution of a controller's method.
}
return
}) |
@kataras, that was a first thing I've tried, but ctx.StopExecution() by some reason did not work for me in this context. Controller function was called anyway despite ctx.StopExecution(). So I the only options were to pass error in context (or unexported field of testCustomStruct) and check it later in controller method. |
Yes, this will work on the new version so you should be fine, if you don't mind you could try out the upcoming release by installing the v11.2.0 branch and give me more feedback if needed ( I added a |
…rror type as a second output value as requested at: kataras#1187 Former-commit-id: 49e29c06aaaa22743354981342c29fc9d5953d0e
Consider the following example:
There is no way to process e.g. JSON conversion errors here. What about supporting second
error
return argument (orint
HTTP error code), just like in normal mapped MVC methods, e.g.:when err != nil, status code 400 (+ err.Error() as body) should be sent as HTTP response and MVC method(s) not called.
The text was updated successfully, but these errors were encountered: