Error handlers

You can define your own handlers when a specific http error code occurs.

Error codes are the http status codes that are bigger or equal to 400, like 404 not found and 500 internal server.

Example code:

package main

import ""

func main(){
    app := iris.New()
    app.OnErrorCode(iris.StatusNotFound, notFound)
    app.OnErrorCode(iris.StatusInternalServerError, internalServerError)
    // to register a handler for all status codes >=400:
    // app.OnAnyErrorCode(handler)
    app.Get("/", index)

func notFound(ctx iris.Context) {
    // when 404 then render the template $views_dir/errors/404.html

func internalServerError(ctx iris.Context) {
    ctx.WriteString("Oups something went wrong, try again")

func index(ctx context.Context) {

results matching ""

    No results matching ""