{"record":{"id":"217fe2ce0ebe2994","repo":"hcengineering/platform","slug":"res-message-217fe2","errorCode":null,"errorMessage":"res.message","messagePattern":"res\\.message","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/sign/src/utils.ts","lineNumber":43,"sourceCode":"\n  const request = {\n    fileId: file\n  }\n\n  const response = await fetch(url, {\n    method: 'POST',\n    headers: {\n      Authorization: `Bearer ${token}`,\n      Accept: 'application/json',\n      'Content-Type': 'application/json'\n    },\n    body: JSON.stringify(request)\n  })\n\n  const res = await response.json()\n\n  if (!response.ok) {\n    throw new Error(res.message)\n  }\n\n  return res.id\n}\n","sourceCodeStart":25,"sourceCodeEnd":48,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/plugins/sign/src/utils.ts#L25-L48","documentation":"signPDF posts the file to the sign service; if the HTTP response is not ok it throws Error(res.message), surfacing the service's error text. The thrown message is whatever the remote endpoint returned in its JSON body, so the error reflects a server-side rejection of the signing request (auth, bad token, malformed request, service failure).","triggerScenarios":"POST to the sign endpoint returns 4xx/5xx with a JSON body; common causes are an expired/invalid token passed to signPDF, an unparsable or oversized PDF, or the signing service being down.","commonSituations":"Token expired between fetching and signing; service deployed behind a proxy that returns HTML errors (res.message then is undefined); wrong endpoint version rejecting the request schema.","solutions":["Check response.status and the full body in the catch to see the actual service error (res.message can be undefined if the body is not the expected JSON)","Refresh the auth token passed to signPDF before retrying","Validate the PDF payload (size, encoding) before sending","Confirm the SignURL endpoint version matches the client request schema"],"exampleFix":"// before\nconst res = await response.json()\nif (!response.ok) {\n  throw new Error(res.message)\n}\n// after\nconst res = await response.json()\nif (!response.ok) {\n  throw new Error(`Sign service error ${response.status}: ${res?.message ?? JSON.stringify(res)}`)\n}","handlingStrategy":"try-catch","validationCode":"const token = getMetadata(presentation.metadata.Token)\nif (token === undefined || token === '') {\n  throw new Error('Cannot sign: no auth token available')\n}\nif (file.length === 0) {\n  throw new Error('Cannot sign: empty PDF payload')\n}","typeGuard":"function isSignError (res: unknown): res is { message?: string, id?: string } {\n  return typeof res === 'object' && res !== null\n}","tryCatchPattern":"try {\n  const id = await signPDF(file, token)\n} catch (err) {\n  if (err instanceof Error && /401|403|token/i.test(err.message ?? '')) {\n    await refreshToken(); return signPDF(file, token)\n  }\n  console.error('Sign service rejected request:', (err as Error).message)\n  throw err\n}","preventionTips":["Refresh tokens proactively before long signing operations","Log response.status alongside the message when wrapping service errors","Validate PDF size/encoding before upload","Monitor the sign service health in deployments that rely on it"],"tags":["http","network","remote-service"],"backgroundTag":"http-request-failed","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}