@vercel/blob - Return more useful error message when retrieveClientToken throws
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- api
Research direction
The relevant code is packages/blob/src/client.ts, at retrieveClientToken and the linked current error location; start by tracing the response body when token retrieval fails. Preserve the specific error text described in the issue instead of only the generic message, and verify the client receives “You do not have permission to upload files” for the shown callback failure.
Written by the indexing model from the issue text.
Description
As a user I should be able to know when retrieveClientToken failed for a specific reason. See the following example:
const jsonResponse = await handleUpload({
body,
request,
onBeforeGenerateToken: async ( pathname: string, /* clientPayload?: string, */ ) => {
// Generate a client token for the browser to upload the file
// ⚠️ Authenticate users before generating the token.
// Otherwise, you're allowing anonymous uploads.
const profile = await getCurrentProfile();
if (!profile) {
console.log('User is not logged in');
throw new Error('Not authenticated');
}
if (!userAccessControl.canUser(profile).createOwn(Resources.UPLOADS).granted) {
console.log('User does not have permission to upload files');
throw new Error('You do not have permission to upload files');
}
return {
allowedContentTypes: ['application/pdf', 'text/plain'],
maximumSizeInBytes: 8_000_000,
tokenPayload: JSON.stringify({ profileId: profile.id })
};
},
onUploadCompleted: async ({ blob, tokenPayload }) => {
// ...
}
});
Assuming the above is set up in a route to handle uploads, I should receive 'You do not have permission to upload files' when the user is authenticated but not permitted to perform uploads, instead of the current 'Failed to retrieve the client token' error.
It seems the library is already set up to return the error in the body to the client, so we could attempt to parse the body for the error message.
- Dominant language
- TypeScript
- Stars
- 595
- Forks
- 101
- Avg merge
- 2h 24m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vercel/storage
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 3/5 1-2 days Newbie friendliness 58/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
fullcalendar/fullcalendar#8106 ·