HandleHTTPError. That method can accept and output any type of arguments to render a response, like the rest of the Controller's method. The
HandleHTTPErroris automatically called by the Framework on HTTP Errors (client 4xx or server 5xx).
mvc.Codeis optional but a good practise to follow. You could register a Context and get its error code through
HandleHTTPError. This is totally optional as
HandleHTTPErrorwill be called automatically on HTTP errors (e.g. client 404).
mvc.Preflight(as we've shown at the previous sections).
mvc.Resultis returned from the Controller's 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 this
errorResponse. Let's design a
GetBymethod which returns
mvc.Result, it returns an
errorResponsewhen "user" was not found in our "database".
mvc.Preflightinterfaces. E.g. a single
responsewhich 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.Preflighton failures. Read more about output values in the dependency injection section.
mvc.Preflightinterface 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
responsetype to a Controller's method. The
Userstructure will be embedded into our
Remember: A structure can complete both mvc.Result and mvc.Preflight interfaces. If Preflight does not return
iris.ErrStopExecutionthen it proceeds with the
Dispatch(mvc.Result) method one. Here is the underline code.
ResultHandlerwhen you want to manipulate or change or log each controllers methods return values per MVC Application or globally.