const response = await fetch('https://api.uploadkit.dev/api/v1/upload/request', { method: 'POST', headers: { 'x-api-key': process.env.UPLOADKIT_API_KEY!, 'Content-Type': 'application/json', }, body: JSON.stringify({ fileName, fileSize, contentType, routeSlug }),});if (!response.ok) { const { error } = await response.json(); switch (error.code) { case 'FILE_TOO_LARGE': throw new Error('Please upload a smaller file.'); case 'FILE_TYPE_NOT_ALLOWED': throw new Error('This file type is not supported.'); case 'RATE_LIMITED': const retryAfter = response.headers.get('Retry-After'); throw new Error(`Too many requests. Try again in ${retryAfter}s.`); case 'TIER_LIMIT_EXCEEDED': throw new Error('Upload quota reached. Upgrade your plan.'); default: throw new Error(error.message); }}
When using the @uploadkitdev/core or @uploadkitdev/react SDK, errors are surfaced via the onError callback with the same code values. You do not need to parse the HTTP response manually.