{"record":{"id":"5ffcca9d86871dd9","repo":"remotion-dev/remotion","slug":"err-instanceof-error-err-message-string-err","errorCode":null,"errorMessage":"${err instanceof Error ? err.message : String(err)}","messagePattern":"\\$\\{err instanceof Error \\? err\\.message : String\\(err\\)\\}","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"packages/lambda-client/src/pages-router-webhook.ts","lineNumber":62,"sourceCode":"\t\t\t\tbody: req.body,\n\t\t\t\tsignatureHeader: req.headers['x-remotion-signature'] as string,\n\t\t\t});\n\n\t\t\t// If code reaches this path, the webhook is authentic.\n\t\t\tconst payload = req.body as WebhookPayload;\n\t\t\tif (payload.type === 'success' && onSuccess) {\n\t\t\t\tawait onSuccess(payload);\n\t\t\t} else if (payload.type === 'timeout' && onTimeout) {\n\t\t\t\tawait onTimeout(payload);\n\t\t\t} else if (payload.type === 'error' && onError) {\n\t\t\t\tawait onError(payload);\n\t\t\t}\n\n\t\t\tres.status(200).json({\n\t\t\t\tsuccess: true,\n\t\t\t});\n\t\t} catch (err) {\n\t\t\tres.status(500).json({\n\t\t\t\tsuccess: false,\n\t\t\t\terror: err instanceof Error ? err.message : String(err),\n\t\t\t});\n\t\t}\n\t};\n};\n","sourceCodeStart":44,"sourceCodeEnd":69,"githubUrl":"https://github.com/remotion-dev/remotion/blob/78fe4bb3fdb5a2cd68724393d63cb223db333fa7/packages/lambda-client/src/pages-router-webhook.ts#L44-L69","documentation":"Generic error surfaced by the Next.js pages-router webhook handler when one of the onSuccess/onTimeout/onError callbacks throws. The thrown value is normalized to a string (Error.message if it is an Error, else String(err)) and returned as a JSON 500 response so the caller sees what failed inside the callback.","triggerScenarios":"Posting a render status payload (type 'success'|'timeout'|'error') to the webhook route, and the corresponding callback (onSuccess/onTimeout/onError) throws synchronously or returns a rejected promise.","commonSituations":"Webhook callback tries to write to a database that is unreachable; callback parses payload fields that are missing; third-party API call inside onSuccess fails; bug in user-supplied callback code; payload shape changed across versions.","solutions":["Inspect the 'error' field of the 500 JSON response to identify which callback threw and why.","Wrap the body of your onSuccess/onTimeout/onError callbacks in try/catch so a callback failure does not surface as a 500.","Log the full payload and callback error server-side for diagnosis, since only the message is returned.","If the error is from an external service, add retries/backoff inside the callback."],"exampleFix":"// before\nconst handler = startWebhookHandler({\n  onSuccess: async (payload) => { await db.markDone(payload.renderId); }\n});\n\n// after\nconst handler = startWebhookHandler({\n  onSuccess: async (payload) => {\n    try { await db.markDone(payload.renderId); }\n    catch (e) { logger.error('onSuccess failed', e); /* do not rethrow */ }\n  }\n});","handlingStrategy":"try-catch","validationCode":"// Validate payload shape before invoking callbacks\nfunction isValidPayload(p: unknown): p is { type: string; renderId: string } {\n  return typeof p === 'object' && p !== null\n    && typeof (p as any).type === 'string'\n    && typeof (p as any).renderId === 'string';\n}\nif (!isValidPayload(payload)) return res.status(400).json({ success: false, error: 'bad payload' });","typeGuard":"const isRenderPayload = (p: unknown): p is { type: 'success'|'timeout'|'error'; renderId: string } =>\n  typeof p === 'object' && p !== null &&\n  ['success','timeout','error'].includes((p as any).type) &&\n  typeof (p as any).renderId === 'string';","tryCatchPattern":"// Each callback must swallow its own errors so the webhook returns 200\nconst safe = (fn) => async (payload) => {\n  try { await fn(payload); }\n  catch (e) { logger.error('webhook callback failed', e); }\n};\nonSuccess: safe(handleSuccess),","preventionTips":["Never let callback errors bubble to the webhook boundary; wrap each handler.","Log the full payload server-side for later diagnosis.","Validate payload shape with a type guard before dispatch."],"tags":["webhook","callback","error-handling","pages-router"],"backgroundTag":null,"analyzedSha":"78fe4bb3fdb5a2cd68724393d63cb223db333fa7","analyzedAt":"2026-08-12T17:18:50.444Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}