File tree Expand file tree Collapse file tree 5 files changed +6
-10
lines changed Expand file tree Collapse file tree 5 files changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -115,6 +115,7 @@ func (c *Context) Abort() {
115
115
// For example, a failed attempt to authentificate a request could use: context.AbortWithStatus(401).
116
116
func (c * Context ) AbortWithStatus (code int ) {
117
117
c .Status (code )
118
+ c .Writer .WriteHeaderNow ()
118
119
c .Abort ()
119
120
}
120
121
Original file line number Diff line number Diff line change @@ -556,7 +556,6 @@ func TestContextAbortWithStatus(t *testing.T) {
556
556
c , w , _ := CreateTestContext ()
557
557
c .index = 4
558
558
c .AbortWithStatus (401 )
559
- c .Writer .WriteHeaderNow ()
560
559
561
560
assert .Equal (t , c .index , abortIndex )
562
561
assert .Equal (t , c .Writer .Status (), 401 )
@@ -607,7 +606,6 @@ func TestContextTypedError(t *testing.T) {
607
606
func TestContextAbortWithError (t * testing.T ) {
608
607
c , w , _ := CreateTestContext ()
609
608
c .AbortWithError (401 , errors .New ("bad input" )).SetMeta ("some input" )
610
- c .Writer .WriteHeaderNow ()
611
609
612
610
assert .Equal (t , w .Code , 401 )
613
611
assert .Equal (t , c .index , abortIndex )
Original file line number Diff line number Diff line change @@ -28,12 +28,9 @@ func ErrorLogger() HandlerFunc {
28
28
func ErrorLoggerT (typ ErrorType ) HandlerFunc {
29
29
return func (c * Context ) {
30
30
c .Next ()
31
- // avoid writting if we already wrote into the response body
32
- if ! c .Writer .Written () {
33
- errors := c .Errors .ByType (typ )
34
- if len (errors ) > 0 {
35
- c .JSON (- 1 , errors )
36
- }
31
+ errors := c .Errors .ByType (typ )
32
+ if len (errors ) > 0 {
33
+ c .JSON (- 1 , errors )
37
34
}
38
35
}
39
36
}
Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ func TestErrorLogger(t *testing.T) {
116
116
117
117
w = performRequest (router , "GET" , "/print" )
118
118
assert .Equal (t , w .Code , 500 )
119
- assert .Equal (t , w .Body .String (), "hola!" )
119
+ assert .Equal (t , w .Body .String (), "hola!{ \" error \" : \" this is an error \" } \n " )
120
120
}
121
121
122
122
func TestSkippingPaths (t * testing.T ) {
Original file line number Diff line number Diff line change @@ -39,5 +39,5 @@ func TestPanicWithAbort(t *testing.T) {
39
39
// RUN
40
40
w := performRequest (router , "GET" , "/recovery" )
41
41
// TEST
42
- assert .Equal (t , w .Code , 500 ) // NOT SURE
42
+ assert .Equal (t , w .Code , 400 )
43
43
}
You can’t perform that action at this time.
0 commit comments