errs: fixed error message not giving proper spacing

This commit is contained in:
Tigor Hutasuhut 2024-04-30 21:39:53 +07:00
parent c26d9fa0b0
commit 1c1c0d03d9
2 changed files with 6 additions and 0 deletions

View file

@ -27,6 +27,9 @@ func (api *API) DevicesUpdate(ctx context.Context, slug string, update *models.D
} }
if err := device.Reload(ctx, api.db); err != nil { if err := device.Reload(ctx, api.db); err != nil {
if err.Error() == "sql: no rows in result set" {
return device, errs.Wrapw(err, "device not found", "slug", slug).Code(404)
}
return device, errs.Wrapw(err, "failed to reload device", "slug", slug) return device, errs.Wrapw(err, "failed to reload device", "slug", slug)
} }

View file

@ -74,6 +74,9 @@ func (er *Err) Error() string {
s := strings.Builder{} s := strings.Builder{}
if er.message != "" { if er.message != "" {
s.WriteString(er.message) s.WriteString(er.message)
if er.origin != nil {
s.WriteString(": ")
}
} }
for unwrap := errors.Unwrap(er); unwrap != nil; { for unwrap := errors.Unwrap(er); unwrap != nil; {
if e, ok := unwrap.(Error); ok && e.GetMessage() != "" { if e, ok := unwrap.(Error); ok && e.GetMessage() != "" {