feat(database): improve error handling (#1633)

This commit is contained in:
ze0s 2024-08-29 09:00:53 +02:00 committed by GitHub
parent cc0cca9f0d
commit accc875960
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 56 additions and 44 deletions

View file

@ -98,7 +98,6 @@ func (r *APIRepo) GetAllAPIKeys(ctx context.Context) ([]domain.APIKey, error) {
if err := rows.Scan(&name, &a.Key, pq.Array(&a.Scopes), &a.CreatedAt); err != nil {
return nil, errors.Wrap(err, "error scanning row")
}
a.Name = name.String
@ -122,9 +121,6 @@ func (r *APIRepo) GetKey(ctx context.Context, key string) (*domain.APIKey, error
row := r.db.handler.QueryRowContext(ctx, query, args...)
if err := row.Err(); err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, domain.ErrRecordNotFound
}
return nil, errors.Wrap(err, "error executing query")
}
@ -133,6 +129,10 @@ func (r *APIRepo) GetKey(ctx context.Context, key string) (*domain.APIKey, error
var name sql.NullString
if err := row.Scan(&name, &apiKey.Key, pq.Array(&apiKey.Scopes), &apiKey.CreatedAt); err != nil {
if errors.Is(err, sql.ErrNoRows) {
return nil, domain.ErrRecordNotFound
}
return nil, errors.Wrap(err, "error scanning row")
}