chore: update not found handler in deleting

This commit is contained in:
Steven
2022-09-03 18:54:22 +08:00
parent 43575e6f54
commit 4743818fe7
8 changed files with 40 additions and 5 deletions

View File

@@ -287,7 +287,7 @@ func findShortcutList(ctx context.Context, tx *sql.Tx, find *api.ShortcutFind) (
}
func deleteShortcut(ctx context.Context, tx *sql.Tx, delete *api.ShortcutDelete) error {
_, err := tx.ExecContext(ctx, `
result, err := tx.ExecContext(ctx, `
PRAGMA foreign_keys = ON;
DELETE FROM shortcut WHERE id = ?
`, delete.ID)
@@ -295,5 +295,10 @@ func deleteShortcut(ctx context.Context, tx *sql.Tx, delete *api.ShortcutDelete)
return FormatError(err)
}
rows, _ := result.RowsAffected()
if rows == 0 {
return &common.Error{Code: common.NotFound, Err: fmt.Errorf("shortcut ID not found: %d", delete.ID)}
}
return nil
}