File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,11 +7,16 @@ type HTTPStatusCodeEr interface {
77 HTTPStatusCode () int
88}
99
10+ // StatusCodeEr defines errors that should return a specific HTTP status code
11+ type StatusCodeEr interface {
12+ StatusCode () int
13+ }
14+
1015// HTTPStatusCode returns the status code that a HTTP handler should return.
1116//
1217// If the error is nil, StatusOK is returned.
1318//
14- // If the error implements HTTPStatusCodeEr, it returns the corresponding status code.
19+ // If the error implements HTTPStatusCodeEr or StatusCodeEr , it returns the corresponding status code.
1520//
1621// It tries to check some stdlib errors (testing the error string, to avoid importing unwanted packages),
1722// and returns appropriate status codes.
@@ -29,6 +34,9 @@ func HTTPStatusCode(err error) int {
2934 if status , ok := err .(HTTPStatusCodeEr ); ok {
3035 return status .HTTPStatusCode ()
3136 }
37+ if status , ok := err .(StatusCodeEr ); ok {
38+ return status .StatusCode ()
39+ }
3240 // Check errors from stdlib. Test string to avoid importing packages
3341 switch err .Error () {
3442 // package os
You can’t perform that action at this time.
0 commit comments