@@ -7,6 +7,7 @@ package context
7
7
8
8
import (
9
9
"fmt"
10
+ "net/http"
10
11
"net/url"
11
12
"strings"
12
13
@@ -64,18 +65,18 @@ type APINotFound struct{}
64
65
// swagger:response redirect
65
66
type APIRedirect struct {}
66
67
67
- // Error responses error message to client with given message.
68
+ // Error responds with an error message to client with given obj as the message.
68
69
// If status is 500, also it prints error to log.
69
70
func (ctx * APIContext ) Error (status int , title string , obj interface {}) {
70
71
var message string
71
72
if err , ok := obj .(error ); ok {
72
73
message = err .Error ()
73
74
} else {
74
- message = obj .( string )
75
+ message = fmt . Sprintf ( "%s" , obj )
75
76
}
76
77
77
- if status == 500 {
78
- log .Error ( "%s: %s" , title , message )
78
+ if status == http . StatusInternalServerError {
79
+ log .ErrorWithSkip ( 1 , "%s: %s" , title , message )
79
80
}
80
81
81
82
ctx .JSON (status , APIError {
@@ -84,6 +85,22 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
84
85
})
85
86
}
86
87
88
+ // InternalServerError responds with an error message to the client with the error as a message
89
+ // and the file and line of the caller.
90
+ func (ctx * APIContext ) InternalServerError (err error ) {
91
+ log .ErrorWithSkip (1 , "InternalServerError: %v" , err )
92
+
93
+ var message string
94
+ if macaron .Env != macaron .PROD {
95
+ message = err .Error ()
96
+ }
97
+
98
+ ctx .JSON (http .StatusInternalServerError , APIError {
99
+ Message : message ,
100
+ URL : setting .API .SwaggerURL ,
101
+ })
102
+ }
103
+
87
104
func genAPILinks (curURL * url.URL , total , pageSize , curPage int ) []string {
88
105
page := NewPagination (total , pageSize , curPage , 0 )
89
106
paginater := page .Paginater
0 commit comments