Iris: [FEATURE REQUEST] `OnErrorCode` doesn't fire `app.Use` and friends

Created on 15 Aug 2020  路  3Comments  路  Source: kataras/iris

Summary

I tried to set an the result of requestid.Get(ctx) into ViewData globally using app.Use(...) -- however, it turns out that neither of these app.Use(...) functions are actually being called when triggered by an OnErrorCode as seen in the screenshot / example code.

Screenshots

image

Versions, etc.

|Thing|Version|
|-|-|
|Golang|1.14.6 linux/amd64|
|Iris|master d0d7679|
|Kernel|5.7.14-200.fc32.x86_64|
|OS|Fedora 32 Workstation|

Sample Code

// ... during app initialization
    app.Use(requestid.New())
    app.Use(func(ctx iris.Context) {
        ctx.ViewData("domain", *domain)
        ctx.ViewData("requestID", requestid.Get(ctx))
        ctx.Next()
    })

// ... when attaching the OnErrorCode
    your := app.Subdomain("your")
    your.Get("/", slashHandler)
    your.OnErrorCode(iris.StatusNotFound, slashHandler)

// ... later in the 404 handler
            ctx.ViewData("canon", fmt.Sprintf("%s%s", *domain, path))
            ctx.ViewData("langCode", lang)
            ctx.ViewData("pageURL", path)
            ctx.ViewData("title", fmt.Sprintf("%s - Not Found", *baseTitle))
            ctx.StatusCode(iris.StatusNotFound)
            if err := ctx.View("404.html"); err != nil {
                ctx.StatusCode(iris.StatusInternalServerError)
                ctx.Writef(err.Error())
            }
implemented idea

Most helpful comment

Yes that's not a BUG, it's behaving like that because we want to. The Party.Use/Done handlers are not running to error codes. This is why the new Party.UseError was introduced a minute ago, this is the same exact issue of #1588. @AlbinoGeek

All 3 comments

Yes that's not a BUG, it's behaving like that because we want to. The Party.Use/Done handlers are not running to error codes. This is why the new Party.UseError was introduced a minute ago, this is the same exact issue of #1588. @AlbinoGeek

UseError has done exactly what I needed here, thank you -- such as protecting error pages of otherwise protected subdomains and parties.

You are welcome, always!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

axetroy picture axetroy  路  4Comments

rhcarvalho picture rhcarvalho  路  4Comments

BharathB23 picture BharathB23  路  3Comments

ZetDeveloper picture ZetDeveloper  路  3Comments

speedwheel picture speedwheel  路  4Comments