-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Beego Status fix #264
Beego Status fix #264
Conversation
Please make the commit title more descriptive. |
Why is that so? Are you sure beego does it on purpose? |
Not sure, I came across this issue when I was working on the cli integration. |
We should probably investigate why it's like that. It's not normal that |
The default value of |
If beego leaves statusCode
Still hard to believe that |
Example app by @chimanjain which shows the issue that is being fixed: package main
import (
"fmt"
"net/http"
"time"
"github.com/beego/beego/v2/server/web/context"
"github.com/beego/beego/v2/server/web"
)
type Date struct {
Date int64 `json:"date"`
}
type Controller struct {
web.Controller
}
func main() {
ctrl := &Controller{}
web.Router("/date", ctrl, "get:GetDate")
web.Router("/datewithstatus", ctrl, "get:GetDateWithStatus")
web.InsertFilterChain("/*", New())
web.Run("127.0.0.1:3000")
}
func (ctrl *Controller) GetDate() {
ctrl.JSONResp(&Date{Date: time.Now().Unix()})
}
func (ctrl *Controller) GetDateWithStatus() {
ctrl.Ctx.ResponseWriter.WriteHeader(http.StatusOK)
ctrl.JSONResp(&Date{Date: time.Now().Unix()})
}
func New() web.FilterChain {
return func(next web.FilterFunc) web.FilterFunc {
return func(ctx *context.Context) {
next(ctx)
fmt.Println(ctx.ResponseWriter.Status)
}
}
} Airbrake API will reject the payload if statusCode is 0, therefore our best assumption is that the endpoint meant to return 200. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but please change the title of the PR and the commit title.
I can see that the commit title didn't change: d67b534 It says "bug fix". Hopefully, next time we can change that as well so that we have a clean git history. |
When the
response status
is ok, the beego application sets it to0
. To fix that when we send the notice to airbrake, we overwrite the status to StatusOK i.e.200