|
|
@ -80,7 +80,7 @@ func initContextWithAnonymousUser(ctx *Context) bool { |
|
|
|
func initContextWithUserSessionCookie(ctx *Context) bool { |
|
|
|
func initContextWithUserSessionCookie(ctx *Context) bool { |
|
|
|
// initialize session
|
|
|
|
// initialize session
|
|
|
|
if err := ctx.Session.Start(ctx); err != nil { |
|
|
|
if err := ctx.Session.Start(ctx); err != nil { |
|
|
|
log.Error(3, "Failed to start session", err) |
|
|
|
ctx.Logger.Error("Failed to start session", "error", err) |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -91,7 +91,7 @@ func initContextWithUserSessionCookie(ctx *Context) bool { |
|
|
|
|
|
|
|
|
|
|
|
query := m.GetSignedInUserQuery{UserId: userId} |
|
|
|
query := m.GetSignedInUserQuery{UserId: userId} |
|
|
|
if err := bus.Dispatch(&query); err != nil { |
|
|
|
if err := bus.Dispatch(&query); err != nil { |
|
|
|
log.Error(3, "Failed to get user with id %v", userId) |
|
|
|
ctx.Logger.Error("Failed to get user with id", "userId", userId) |
|
|
|
return false |
|
|
|
return false |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ctx.SignedInUser = query.Result |
|
|
|
ctx.SignedInUser = query.Result |
|
|
@ -185,7 +185,7 @@ func initContextWithApiKeyFromSession(ctx *Context) bool { |
|
|
|
|
|
|
|
|
|
|
|
keyQuery := m.GetApiKeyByIdQuery{ApiKeyId: keyId.(int64)} |
|
|
|
keyQuery := m.GetApiKeyByIdQuery{ApiKeyId: keyId.(int64)} |
|
|
|
if err := bus.Dispatch(&keyQuery); err != nil { |
|
|
|
if err := bus.Dispatch(&keyQuery); err != nil { |
|
|
|
log.Error(3, "Failed to get api key by id", err) |
|
|
|
ctx.Logger.Error("Failed to get api key by id", "id", keyId, "error", err) |
|
|
|
return false |
|
|
|
return false |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
apikey := keyQuery.Result |
|
|
|
apikey := keyQuery.Result |
|
|
@ -202,7 +202,7 @@ func initContextWithApiKeyFromSession(ctx *Context) bool { |
|
|
|
// Handle handles and logs error by given status.
|
|
|
|
// Handle handles and logs error by given status.
|
|
|
|
func (ctx *Context) Handle(status int, title string, err error) { |
|
|
|
func (ctx *Context) Handle(status int, title string, err error) { |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Error(4, "%s: %v", title, err) |
|
|
|
ctx.Logger.Error(title, "error", err) |
|
|
|
if setting.Env != setting.PROD { |
|
|
|
if setting.Env != setting.PROD { |
|
|
|
ctx.Data["ErrorMsg"] = err |
|
|
|
ctx.Data["ErrorMsg"] = err |
|
|
|
} |
|
|
|
} |
|
|
@ -223,9 +223,7 @@ func (ctx *Context) Handle(status int, title string, err error) { |
|
|
|
|
|
|
|
|
|
|
|
func (ctx *Context) JsonOK(message string) { |
|
|
|
func (ctx *Context) JsonOK(message string) { |
|
|
|
resp := make(map[string]interface{}) |
|
|
|
resp := make(map[string]interface{}) |
|
|
|
|
|
|
|
|
|
|
|
resp["message"] = message |
|
|
|
resp["message"] = message |
|
|
|
|
|
|
|
|
|
|
|
ctx.JSON(200, resp) |
|
|
|
ctx.JSON(200, resp) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -237,7 +235,7 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) { |
|
|
|
resp := make(map[string]interface{}) |
|
|
|
resp := make(map[string]interface{}) |
|
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.Error(4, "%s: %v", message, err) |
|
|
|
ctx.Logger.Error(message, "error", err) |
|
|
|
if setting.Env != setting.PROD { |
|
|
|
if setting.Env != setting.PROD { |
|
|
|
resp["error"] = err.Error() |
|
|
|
resp["error"] = err.Error() |
|
|
|
} |
|
|
|
} |
|
|
|