{"record":{"id":"e604c15479b1c83b","repo":"srbhr/Resume-Matcher","slug":"upload-failed-for-filetoupload-file-name-statu","errorCode":null,"errorMessage":"Upload failed for ${fileToUpload.file.name}. Status: ${response.status} ${response.statusText} - Server response: ${errorText...}","messagePattern":"Upload failed for (.+?)\\. Status: (.+?) (.+?) - Server response: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/frontend/hooks/use-file-upload.ts","lineNumber":245,"sourceCode":"\n      try {\n        const response = await fetch(uploadUrl, {\n          method: 'POST',\n          body: formData,\n        });\n\n        let responseData: Record<string, unknown> = {}; // Initialize for broader scope\n        const contentType = response.headers.get('content-type');\n\n        if (!response.ok) {\n          let errorDetail = `Upload failed for ${fileToUpload.file.name}. Status: ${response.status} ${response.statusText}`;\n          try {\n            const errorText = await response.text();\n            errorDetail += ` - Server response: ${errorText.substring(0, 200)}${errorText.length > 200 ? '...' : ''}`;\n          } catch (textError: unknown) {\n            console.warn('Could not read error response text:', textError);\n          }\n          throw new Error(errorDetail);\n        }\n\n        if (contentType && contentType.includes('application/json')) {\n          responseData = (await response.json()) as Record<string, unknown>;\n        } else {\n          // Handle non-JSON or missing Content-Type response if necessary,\n          // or assume success if response.ok and no JSON is expected for some cases.\n          // For now, we'll assume JSON is expected on success.\n          console.warn(\n            `Response for ${fileToUpload.file.name} was not JSON. Content-Type: ${contentType}`\n          );\n          // If JSON is strictly required, this could be an error condition:\n          // throw new Error(`Unexpected response type: ${contentType}. Expected JSON.`);\n        }\n\n        const successfullyUploadedFile: FileWithPreview = {\n          ...fileToUpload,\n          file: {","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/srbhr/Resume-Matcher/blob/116f9cc3b00e1ac91734a6c2679bf41ea64a0edc/apps/frontend/hooks/use-file-upload.ts#L227-L263","documentation":"useFileUpload builds a descriptive Error when the upload endpoint returns a non-OK HTTP response. It first reads the response body as text (truncated to 200 chars) and appends it to a message containing the filename, status code, and statusText, then throws. This surfaces server-side rejection reasons (validation, auth, size limits) directly to the caller.","triggerScenarios":"Any uploadFile POST to the upload endpoint returning status >= 400: 401 unauthenticated session, 403 CSRF/permission denied, 413 file too large, 415 unsupported file type, 422 validation failure, or 5xx backend crash.","commonSituations":"User uploads a PDF/DOCX larger than the server's configured max size; expired session cookie causes 401; backend rejects the file extension; reverse proxy returns 502 during backend restart.","solutions":["Log the full error message and inspect the embedded status code and server response text to identify the server-side reason","Check authentication: ensure the session cookie is present and not expired (401/403)","Verify the file size is under the server's upload limit and the file type is supported","Retry after fixing the input; for 5xx, check backend logs and retry once the service is healthy"],"exampleFix":"// before\nawait uploadFile(file); // throws generic unhandled error\n// after\ntry {\n  await uploadFile(file);\n} catch (e) {\n  if (e.message.includes('Status: 413')) showMsg('File too large');\n  else if (e.message.includes('Status: 401')) await reauthAndRetry();\n  else showMsg(`Upload failed: ${e.message}`);\n}","handlingStrategy":"try-catch","validationCode":"function canUpload(file: File) {\n  const MAX = 50 * 1024 * 1024;\n  const OK = ['application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'text/plain'];\n  return file.size > 0 && file.size <= MAX && OK.includes(file.type);\n}","typeGuard":"function isUploadError(e: unknown): e is Error & { status?: number } {\n  const m = e instanceof Error ? e.message.match(/Status: (\\d{3})/) : null;\n  if (e instanceof Error && m) (e as any).status = Number(m[1]);\n  return e instanceof Error;\n}","tryCatchPattern":"try {\n  await uploadFile(file);\n} catch (e) {\n  const m = e instanceof Error ? e.message.match(/Status: (\\d{3})/) : null;\n  if (m && ['401','403'].includes(m[1])) reauth();\n  else if (m === '413' || m?.[1] === '413') showMsg('File too large');\n  else showMsg(`Upload failed: ${e instanceof Error ? e.message : String(e)}`);\n}","preventionTips":["Validate file size and MIME type client-side before uploading","Refresh the session/CSRF token before long-running flows","Show the server's error text (already embedded in the message) in the UI so users can self-diagnose","Monitor upload endpoint error rates by status code"],"tags":["http","upload","frontend","error-handling"],"backgroundTag":"http-error-response","analyzedSha":"116f9cc3b00e1ac91734a6c2679bf41ea64a0edc","analyzedAt":"2026-08-28T22:51:40.999Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}