When the request is being recorded, the body is overwritten before sending the response by the error status code handler. This doesn't happen when the request is not recorded.
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
app.Handle("POST", "/fail", func(ctx iris.Context) {
ctx.Record()
ctx.StatusCode(500)
if _, err := ctx.Recorder().Write([]byte("My error message")); err != nil {
panic(err)
}
ctx.Next()
})
app.Run(iris.Addr(":8080"))
}
Response:
Internal Server Error
This can be hotfix by setting the option DisableAutoFireStatusCode to true
But, I think that the request should have the same behaviour when it's being recorded and when it's not.
package main
import (
"fmt"
"github.com/kataras/iris/v12"
)
func main() {
app := iris.New()
app.Handle("POST", "/fail", func(ctx iris.Context) {
// ctx.Record()
ctx.StatusCode(500)
if _, err := ctx.Recorder().Write([]byte("My error message")); err != nil {
panic(err)
}
ctx.Next()
})
app.Run(iris.Addr(":8080"))
}
Response:
My error message
When the request is being recorded, the body is overwritten before sending the response by the error status code handler. This doesn't happen when the request is not recorded.
Response:
Internal Server ErrorThis can be hotfix by setting the option
DisableAutoFireStatusCodetotrueBut, I think that the request should have the same behaviour when it's being recorded and when it's not.
Response:
My error message