diff --git a/client/client.go b/client/client.go index 4281a28a..3b93f6fb 100644 --- a/client/client.go +++ b/client/client.go @@ -173,6 +173,34 @@ func (c *Client) Create(model interface{}) (uint, error) { return uint(id), nil } +func (c *Client) Update(model orm.IDer) (uint, error) { + var response renderer.JsonResponse + data, err := json.Marshal(model) + if err != nil { + return 0, err + } + + resp, err := c.SendRequest("POST", fmt.Sprintf("/api/%s/%d/update?format=json", reflect.ModelNameLowerPlural(model), model.GetID()), data) + if err != nil { + return 0, err + } + + if err := json.Unmarshal(resp, &response); err != nil { + return 0, err + } + + if string(response.Error) != "" { + return 0, errors.New(string(response.Error)) + } + + id, err := strconv.Atoi(string(response.Result)) + if err != nil { + return 0, err + } + + return uint(id), nil +} + func (c *Client) Delete(model orm.IDer) (uint, error) { var response renderer.JsonResponse data, err := json.Marshal(model) diff --git a/handlers/handlers.go b/handlers/handlers.go index cb325191..df4228e1 100644 --- a/handlers/handlers.go +++ b/handlers/handlers.go @@ -297,19 +297,6 @@ func DefaultRecoverHandler(next http.Handler) http.Handler { return http.HandlerFunc(fn) } -// func (h *Handlers) setFlashMessage(w http.ResponseWriter, r *http.Request, key string) error { -// session, err := h.CookieStore.Get(r, "flash-session") -// if err != nil { -// return err -// } -// session.AddFlash(i18n.FlashMessages[key][h.Config.Language]) -// err = session.Save(r, w) -// if err != nil { -// return err -// } -// return nil -// } - func (h *Handlers) hasPermission(r *http.Request, path string) bool { claims := getClaims(r) role := claims["role"].(string) @@ -406,8 +393,9 @@ func respondWithError(h *Handlers, w http.ResponseWriter, r *http.Request, err e if format == "" { format = renderer.GetContentFormat(r) } + panicMsg := fmt.Sprintf("PANIC: %v\n\n== STACKTRACE ==\n%s", err, debug.Stack()) if h.Config.LogLevel > config.LOG_LEVEL_OFF { - log.Println("Error:", err) + log.Println("Error:", panicMsg) } // FIXME: this call could be superflous when an error occurs // in a template execution