Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upError handling in MVC mapper functions #1187
Comments
kataras
added this to the v11.2.0 milestone
Feb 15, 2019
This comment has been minimized.
This comment has been minimized.
|
@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
added
status:implemented
and removed
status:in-progress
labels
Feb 15, 2019
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
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 |


pantonov commentedFeb 14, 2019
•
edited
Consider the following example:
There is no way to process e.g. JSON conversion errors here. What about supporting second
errorreturn argument (orintHTTP 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.