HandleHTTPError
. That method can accept and output any type of arguments to render a response, like the rest of the Controller's method. The HandleHTTPError
is automatically called by the Framework on HTTP Errors (client 4xx or server 5xx).mvc.Code
is optional but a good practise to follow. You could register a Context and get its error code through ctx.GetStatusCode()
.HandleHTTPError
. This is totally optional as HandleHTTPError
will be called automatically on HTTP errors (e.g. client 404).HandleHTTPError
in the same Party
, you need to use the RouteOverlap
feature as shown in the authenticated-controller example.mvc.Result
or mvc.Preflight
(as we've shown at the previous sections).mvc.Result
mvc.Result
is returned from the Controller's method.mvc.Result
through the Dispatch(iris.Context)
method.Remember: mvc.View, Response and e.t.c are all mvc.Result at the end, so you can call their Dispatch method to render even if a specific method cannot output values (like thisDispatch
one).
errorResponse
. Let's design a GetBy
method which returns mvc.Result
, it returns an errorResponse
when "user" was not found in our "database".mvc.Preflight
mvc.Result
or mvc.Preflight
interfaces. E.g. a single response
which can output data or error. Or even return different types at all, e.g. return a user struct
(JSON by default) on valid requests and userError mvc.Preflight
on failures. Read more about output values in the dependency injection section.mvc.Preflight
interface which will run right before the render of response
, it can manipulate an object right before it is rendered or handle rendering all by it self by returning the iris.ErrStopExecution
error.response
type to a Controller's method. The User
structure will be embedded into our response.Data
field.Remember: A structure can complete both mvc.Result and mvc.Preflight interfaces. If Preflight does not returniris.ErrStopExecution
then it proceeds with theDispatch
(mvc.Result) method one. Here is the underline code.
ResultHandler
when you want to manipulate or change or log each controllers methods return values per MVC Application or globally.