@@ -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,7 +65,7 @@ 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
@@ -74,8 +75,8 @@ func (ctx *APIContext) Error(status int, title string, obj interface{}) {
74
75
message = obj .(string )
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,17 @@ 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
+ ctx .JSON (http .StatusInternalServerError , APIError {
94
+ Message : err .Error (),
95
+ URL : setting .API .SwaggerURL ,
96
+ })
97
+ }
98
+
87
99
func genAPILinks (curURL * url.URL , total , pageSize , curPage int ) []string {
88
100
page := NewPagination (total , pageSize , curPage , 0 )
89
101
paginater := page .Paginater
0 commit comments