refactor(api): sqlite error check uses new for type assertion
This commit is contained in:
parent
b23ac7617e
commit
efd2b6b187
|
@ -33,8 +33,7 @@ func (api *API) DevicesCreate(ctx context.Context, params *models.Device) (devic
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var sqliteErr sqlite3.Error
|
if sqliteErr := new(sqlite3.Error); errors.As(err, sqliteErr) {
|
||||||
if errors.As(err, &sqliteErr) {
|
|
||||||
if sqliteErr.Code == sqlite3.ErrConstraint {
|
if sqliteErr.Code == sqlite3.ErrConstraint {
|
||||||
return nil, errs.
|
return nil, errs.
|
||||||
Wrapw(sqliteErr, "device already exists", "params", params).
|
Wrapw(sqliteErr, "device already exists", "params", params).
|
||||||
|
|
|
@ -12,10 +12,10 @@ func (api *API) GetDevice(ctx context.Context, slug string) (device *models.Devi
|
||||||
device, err = models.FindDevice(ctx, api.db, slug)
|
device, err = models.FindDevice(ctx, api.db, slug)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() == "sql: no rows in result set" {
|
if err.Error() == "sql: no rows in result set" {
|
||||||
return device, errs.Wrapw(err, "device not found", "device", device).Code(connect.CodeNotFound)
|
return device, errs.Wrapw(err, "device not found", "slug", slug).Code(connect.CodeNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
return device, errs.Wrapw(err, "failed to find device", "device", device)
|
return device, errs.Wrapw(err, "failed to find device", "slug", slug)
|
||||||
}
|
}
|
||||||
|
|
||||||
return device, nil
|
return device, nil
|
||||||
|
|
Loading…
Reference in a new issue