hcengineering/platform · error

res.message

Error message

res.message

What it means

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).

Source

Thrown at plugins/sign/src/utils.ts:43

  const request = {
    fileId: file
  }

  const response = await fetch(url, {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${token}`,
      Accept: 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(request)
  })

  const res = await response.json()

  if (!response.ok) {
    throw new Error(res.message)
  }

  return res.id
}

View on GitHub (pinned to 63e28dc964)

Solutions

  1. 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)
  2. Refresh the auth token passed to signPDF before retrying
  3. Validate the PDF payload (size, encoding) before sending
  4. Confirm the SignURL endpoint version matches the client request schema

Example fix

// before
const res = await response.json()
if (!response.ok) {
  throw new Error(res.message)
}
// after
const res = await response.json()
if (!response.ok) {
  throw new Error(`Sign service error ${response.status}: ${res?.message ?? JSON.stringify(res)}`)
}
Defensive patterns

Strategy: try-catch

Validate before calling

const token = getMetadata(presentation.metadata.Token)
if (token === undefined || token === '') {
  throw new Error('Cannot sign: no auth token available')
}
if (file.length === 0) {
  throw new Error('Cannot sign: empty PDF payload')
}

Type guard

function isSignError (res: unknown): res is { message?: string, id?: string } {
  return typeof res === 'object' && res !== null
}

Try / catch

try {
  const id = await signPDF(file, token)
} catch (err) {
  if (err instanceof Error && /401|403|token/i.test(err.message ?? '')) {
    await refreshToken(); return signPDF(file, token)
  }
  console.error('Sign service rejected request:', (err as Error).message)
  throw err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/217fe2ce0ebe2994. Report an issue: GitHub.