Errors: Make errors the same in dev as prod (#77366)
When running in dev mode, error messages would contain an additional "error" property alongside "message". Since this causes confusion, that has been removed and now error messages are the same both modes (using "message").
This commit is contained in:
@@ -46,11 +46,9 @@ func (ctx *ReqContext) Handle(cfg *setting.Cfg, status int, title string, err er
|
||||
Theme string
|
||||
ErrorMsg error
|
||||
}{title, "Grafana", cfg.AppSubURL, "dark", nil}
|
||||
|
||||
if err != nil {
|
||||
ctx.Logger.Error(title, "error", err)
|
||||
if setting.Env != setting.Prod {
|
||||
data.ErrorMsg = err
|
||||
}
|
||||
}
|
||||
|
||||
ctx.HTML(status, cfg.ErrTemplateName, data)
|
||||
@@ -75,10 +73,6 @@ func (ctx *ReqContext) JsonApiErr(status int, message string, err error) {
|
||||
} else {
|
||||
ctx.Logger.Warn(message, "error", err, "traceID", traceID)
|
||||
}
|
||||
|
||||
if setting.Env != setting.Prod {
|
||||
resp["error"] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
switch status {
|
||||
|
||||
@@ -69,19 +69,16 @@ func TestDataProxy(t *testing.T) {
|
||||
// Tests request to datasource proxy service
|
||||
func TestDatasourceProxy_proxyDatasourceRequest(t *testing.T) {
|
||||
tcs := []struct {
|
||||
name string
|
||||
dsURL string
|
||||
expectedErrorMsg string
|
||||
name string
|
||||
dsURL string
|
||||
}{
|
||||
{
|
||||
name: "Empty datasource URL will return a 400 HTTP status code",
|
||||
dsURL: "",
|
||||
expectedErrorMsg: "validation of data source URL \"\" failed: empty URL string",
|
||||
name: "Empty datasource URL will return a 400 HTTP status code",
|
||||
dsURL: "",
|
||||
},
|
||||
{
|
||||
name: "Invalid datasource URL will return a 400 HTTP status code",
|
||||
dsURL: "://host/path",
|
||||
expectedErrorMsg: "validation of data source URL \"://host/path\" failed: parse \"://host/path\": missing protocol scheme",
|
||||
name: "Invalid datasource URL will return a 400 HTTP status code",
|
||||
dsURL: "://host/path",
|
||||
},
|
||||
}
|
||||
for _, tc := range tcs {
|
||||
@@ -124,7 +121,6 @@ func TestDatasourceProxy_proxyDatasourceRequest(t *testing.T) {
|
||||
|
||||
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||
require.Equal(t, fmt.Sprintf("Invalid data source URL: %q", tc.dsURL), jsonBody["message"])
|
||||
require.Equal(t, tc.expectedErrorMsg, jsonBody["error"])
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,6 @@ func TestGetUserFromLDAPAPIEndpoint_OrgNotfound(t *testing.T) {
|
||||
var resMap map[string]interface{}
|
||||
err = json.Unmarshal(bodyBytes, &resMap)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "unable to find organization with ID '2'", resMap["error"])
|
||||
assert.Equal(t, "An organization was not found - Please verify your LDAP configuration", resMap["message"])
|
||||
}
|
||||
|
||||
@@ -499,7 +498,6 @@ func TestPostSyncUserWithLDAPAPIEndpoint_WhenGrafanaAdmin(t *testing.T) {
|
||||
var resMap map[string]interface{}
|
||||
err = json.Unmarshal(bodyBytes, &resMap)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "did not find a user", resMap["error"])
|
||||
assert.Equal(t, "Refusing to sync grafana super admin \"ldap-daniel\" - it would be disabled", resMap["message"])
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ func TestProvisioningApi(t *testing.T) {
|
||||
response := sut.RoutePutPolicyTree(&rc, tree)
|
||||
|
||||
require.Equal(t, 400, response.Status())
|
||||
expBody := `{"error":"invalid object specification: invalid policy tree","message":"invalid object specification: invalid policy tree"}`
|
||||
expBody := `{"message":"invalid object specification: invalid policy tree"}`
|
||||
require.Equal(t, expBody, string(response.Body()))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user