mirror of
https://github.com/lobehub/lobehub
synced 2026-04-21 17:47:27 +00:00
♻️ refactor: narrow storage_block error typing in upload action
Some checks are pending
E2E CI / Check Duplicate Run (push) Waiting to run
E2E CI / Test Web App (push) Blocked by required conditions
Test CI / Check Duplicate Run (push) Waiting to run
Test CI / Test Packages (push) Blocked by required conditions
Test CI / Test App (shard 1/3) (push) Blocked by required conditions
Test CI / Test App (shard 2/3) (push) Blocked by required conditions
Test CI / Test App (shard 3/3) (push) Blocked by required conditions
Test CI / Merge and Upload App Coverage (push) Blocked by required conditions
Test CI / Test Desktop App (push) Blocked by required conditions
Test CI / Test Database (push) Blocked by required conditions
Some checks are pending
E2E CI / Check Duplicate Run (push) Waiting to run
E2E CI / Test Web App (push) Blocked by required conditions
Test CI / Check Duplicate Run (push) Waiting to run
Test CI / Test Packages (push) Blocked by required conditions
Test CI / Test App (shard 1/3) (push) Blocked by required conditions
Test CI / Test App (shard 2/3) (push) Blocked by required conditions
Test CI / Test App (shard 3/3) (push) Blocked by required conditions
Test CI / Merge and Upload App Coverage (push) Blocked by required conditions
Test CI / Test Desktop App (push) Blocked by required conditions
Test CI / Test Database (push) Blocked by required conditions
Replace `(error as any)?.message` with `instanceof Error` guard and tighten the errorKeyMap type via `satisfies Record<StorageBlockReason, string>` so new StorageBlockReason variants are caught at compile time.
This commit is contained in:
parent
5400c07bfa
commit
d1c2c60242
1 changed files with 16 additions and 4 deletions
|
|
@ -183,24 +183,36 @@ export class FileUploadActionImpl {
|
|||
|
||||
return { ...data, dimensions, filename: file.name };
|
||||
} catch (error) {
|
||||
const errorMessage = (error as any)?.message ?? '';
|
||||
const errorMessage = error instanceof Error ? error.message : '';
|
||||
|
||||
// Handle structured storage block reasons (storage_block:<reason>)
|
||||
if (errorMessage.startsWith('storage_block:')) {
|
||||
const reason = errorMessage.replace('storage_block:', '');
|
||||
onStatusUpdate?.({ id: statusId, type: 'removeFile' });
|
||||
|
||||
const errorKeyMap: Record<string, string> = {
|
||||
// Keep this union in sync with cloud `StorageBlockReason` in
|
||||
// src/server/services/storageOverage/index.ts (cloud repo).
|
||||
type StorageBlockReason =
|
||||
| 'monthly_cap_reached'
|
||||
| 'no_payment_method'
|
||||
| 'overage_not_enabled'
|
||||
| 'subscription_past_due'
|
||||
| 'subscription_unpaid'
|
||||
| 'upgrade_required';
|
||||
|
||||
const errorKeyMap = {
|
||||
monthly_cap_reached: 'upload.storageBlock.monthlyCapReached',
|
||||
no_payment_method: 'upload.storageBlock.noPaymentMethod',
|
||||
overage_not_enabled: 'upload.storageBlock.overageNotEnabled',
|
||||
subscription_past_due: 'upload.storageBlock.subscriptionPastDue',
|
||||
subscription_unpaid: 'upload.storageBlock.subscriptionUnpaid',
|
||||
upgrade_required: 'upload.storageBlock.upgradeRequired',
|
||||
};
|
||||
} as const satisfies Record<StorageBlockReason, string>;
|
||||
|
||||
const key = (errorKeyMap as Record<string, string>)[reason];
|
||||
|
||||
notification.error({
|
||||
description: t(errorKeyMap[reason] ?? 'upload.storageLimitExceeded', { ns: 'error' }),
|
||||
description: t(key ?? 'upload.storageLimitExceeded', { ns: 'error' }),
|
||||
message: t('upload.uploadFailed', { ns: 'error' }),
|
||||
});
|
||||
return;
|
||||
|
|
|
|||
Loading…
Reference in a new issue