@@ -7,7 +7,6 @@ package revel
7
7
import (
8
8
"errors"
9
9
"fmt"
10
- "github.com/revel/revel/logger"
11
10
"io"
12
11
"net/http"
13
12
"os"
@@ -16,6 +15,8 @@ import (
16
15
"runtime"
17
16
"strings"
18
17
"time"
18
+
19
+ "github.com/revel/revel/logger"
19
20
)
20
21
21
22
// Controller Revel's controller structure that gets embedded in user defined
@@ -41,6 +42,7 @@ type Controller struct {
41
42
Validation * Validation // Data validation helpers
42
43
Log logger.MultiLogger // Context Logger
43
44
}
45
+
44
46
// The map of controllers, controllers are mapped by using the namespace|controller_name as the key
45
47
var controllers = make (map [string ]* ControllerType )
46
48
var controllerLog = RevelLog .New ("section" , "controller" )
@@ -119,8 +121,16 @@ func (c *Controller) SetCookie(cookie *http.Cookie) {
119
121
c .Response .Out .internalHeader .SetCookie (cookie .String ())
120
122
}
121
123
124
+ type ErrorCoder interface {
125
+ HTTPCode () int
126
+ }
127
+
122
128
func (c * Controller ) RenderError (err error ) Result {
123
- c .setStatusIfNil (http .StatusInternalServerError )
129
+ if coder , ok := err .(ErrorCoder ); ok {
130
+ c .setStatusIfNil (coder .HTTPCode ())
131
+ } else {
132
+ c .setStatusIfNil (http .StatusInternalServerError )
133
+ }
124
134
125
135
return ErrorResult {c .ViewArgs , err }
126
136
}
@@ -486,9 +496,6 @@ func findControllers(appControllerType reflect.Type) (indexes [][]int) {
486
496
return
487
497
}
488
498
489
-
490
-
491
-
492
499
// RegisterController registers a Controller and its Methods with Revel.
493
500
func RegisterController (c interface {}, methods []* MethodType ) {
494
501
// De-star the controller type
0 commit comments