feat(storage): point a full trial account at the upgrade rather than at nothing

Being told "storage limit exceeded" when the limit is the free trial's three
gigabytes is a dead end. The account is not full because it stores a lot; it is
capped because it has not subscribed, and deleting files buys back very little.

The refusal now says which ceiling it is and carries its own error code, so the
toast can offer a link to the billing settings on the trial ceiling and stay
quiet on the paid one, where subscribing changes nothing.

The code had to survive the trip to the toast, which meant the upload helpers
throwing something that carries it rather than a bare Error. Two places were
dropping the server's message on the floor entirely: adding a version reported
"Failed to initialize upload" whatever the server said, and every asset upload
in the pane rewrote its own failure text.
This commit is contained in:
2026-08-18 11:42:30 +03:00
parent 63288761ed
commit 6561e0817e
10 changed files with 239 additions and 40 deletions
@@ -12,6 +12,7 @@ import {
import type { VersionActionsConfig, VideoData } from '@/components/video-page/types';
import { resolvePublicBunnyCdnHostname } from '@/lib/bunny-cdn';
import { cleanupPendingR2VideoUpload, uploadVideoToR2 } from '@/lib/client/r2-video-upload';
import { apiRequestError, toastApiError } from '@/lib/client/api-error';
/** What a failed version upload has to undo, depending on which provider it started on. */
type PendingVersionCleanup =
@@ -113,7 +114,13 @@ export function useVersionActions({
body: JSON.stringify({ title, sizeBytes: file.size.toString() }),
});
if (!initRes.ok) throw new Error('Failed to initialize upload');
if (!initRes.ok) {
const initPayload = (await initRes.json().catch(() => null)) as {
error?: string;
code?: string;
} | null;
throw apiRequestError(initPayload, 'Failed to initialize upload');
}
const {
data: { videoId: bunnyVideoId, libraryId, signature, expirationTime, uploadToken },
} = await initRes.json();
@@ -236,7 +243,7 @@ export function useVersionActions({
if (!res.ok) {
const data = await res.json().catch(() => null);
throw new Error(data?.error || 'Failed to create version');
throw apiRequestError(data, 'Failed to create version');
}
const versionData = await res.json();
@@ -277,7 +284,7 @@ export function useVersionActions({
}
}
console.error('Failed to create version:', errorObj);
toast.error(errorObj.message || 'Failed to create version');
toastApiError(errorObj, 'Failed to create version');
} finally {
setIsCreatingVersion(false);
setNewVersionUploadProgress(0);