{"record":{"id":"e3484027abbfdd71","repo":"gitroomhq/postiz-app","slug":"handleerror-value-failed-to-upload-the-vide","errorCode":null,"errorMessage":"${handleError?.value || 'Failed to upload the video to TikTok'}","messagePattern":"\\$\\{handleError\\?\\.value \\|\\| 'Failed to upload the video to TikTok'\\}","errorType":"exception","errorClass":"BadBody","httpStatus":null,"severity":"error","filePath":"libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts","lineNumber":761,"sourceCode":"        method: 'PUT',\n        headers: {\n          'Content-Type': contentType,\n          'Content-Length': String(contentLength),\n          'Content-Range': `bytes ${start}-${end}/${videoSize}`,\n        },\n        body,\n        // Required by undici when streaming a request body.\n        duplex: 'half',\n      } as any);\n\n      if (\n        upload.status !== 200 &&\n        upload.status !== 201 &&\n        upload.status !== 206\n      ) {\n        const text = await upload.text().catch(() => '{}');\n        const handleError = this.handleErrors(text);\n        throw new BadBody(\n          'tiktok-error-upload',\n          text,\n          Buffer.from(text),\n          handleError?.value || 'Failed to upload the video to TikTok'\n        );\n      }\n    }\n  }\n\n  private buildTikokSourceInfoBody(\n    firstPost: PostDetails<TikTokDto>,\n    videoSize?: number\n  ) {\n    const isPhoto = !hasExtension(firstPost?.media?.[0]?.path, 'mp4');\n\n    // TikTok photo posts only support PULL_FROM_URL, there is no FILE_UPLOAD\n    // path for photos, so this branch keeps pulling from the URL.\n    if (isPhoto) {","sourceCodeStart":743,"sourceCodeEnd":779,"githubUrl":"https://github.com/gitroomhq/postiz-app/blob/0f1647f7491a217d43eb5ae7a480484bdf0aff3e/libraries/nestjs-libraries/src/integrations/social/tiktok.provider.ts#L743-L779","documentation":"uploadTikTokVideoBytes got a non-2xx/206 response when PUTting a video chunk to TikTok's upload endpoint. The message comes from TikTok's error payload when parseable, otherwise the generic 'Failed to upload the video to TikTok'.","triggerScenarios":"TikTok chunk upload PUT returns 4xx/5xx: expired upload_url, wrong Content-Length/Content-Range for the chunk, auth token revoked, or rate limiting during a large multi-chunk upload.","commonSituations":"Long-running uploads where TikTok's upload_url expires mid-way; clock skew breaking signed URLs; retrying an already-completed upload session; network interruptions causing partial chunk writes.","solutions":["Inspect the raw body attached to the BadBody — it contains TikTok's specific error code/message","Ensure chunk size, Content-Range and total Content-Length match what initializeUpload negotiated","Retry the whole post: a fresh upload session gets a new upload_url","If error is auth-related (expired_token), refresh the TikTok token and reconnect the channel"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"catch (e) { if (e instanceof BadBody && e.code === 'tiktok-error-upload') { const detail = e.body?.toString(); /* parse TikTok error, decide retry vs surface */ } throw e; }","preventionTips":["Match chunk offsets and Content-Length exactly to the initialized upload session","Complete uploads quickly so TikTok's upload_url does not expire","Retry the whole post (new upload session) rather than a single chunk after long delays"],"tags":["tiktok","video-upload","chunked-upload","api-error"],"backgroundTag":"social-media-upload-rejected","analyzedSha":"0f1647f7491a217d43eb5ae7a480484bdf0aff3e","analyzedAt":"2026-08-27T12:09:55.020Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}