{"record":{"id":"fa1a42c8ed54835b","repo":"Budibase/budibase","slug":"custom-rest-template-not-found-fa1a42","errorCode":null,"errorMessage":"Custom REST template not found","messagePattern":"Custom REST template not found","errorType":"http","errorClass":"HTTPError","httpStatus":404,"severity":"error","filePath":"packages/server/src/sdk/workspace/restTemplates.ts","lineNumber":181,"sourceCode":"export const create = async (params: CreateCustomRestTemplateParams) =>\n  withCustomRestTemplateLock({\n    resource: \"workspace\",\n    task: () => createWithoutLock(params),\n  })\n\nconst updateWithoutLock = async ({\n  restTemplateId,\n  name,\n  description,\n}: {\n  restTemplateId: CustomRestTemplateId\n  name: string\n  description: string\n}): Promise<RestTemplate> => {\n  const db = context.getWorkspaceDB()\n  const document = await db.tryGet<CustomRestTemplateDocument>(restTemplateId)\n  if (!document?._rev) {\n    throw new HTTPError(\"Custom REST template not found\", 404)\n  }\n\n  const normalizedName = kebabCase(name)\n  if (!normalizedName) {\n    throw new HTTPError(\"Template name must contain letters or numbers\", 400)\n  }\n  const duplicate = (await fetch()).find(\n    template =>\n      template.id !== restTemplateId &&\n      kebabCase(template.name) === normalizedName\n  )\n  if (duplicate) {\n    throw new HTTPError(\n      `A custom REST template named \"${name.trim()}\" already exists`,\n      409\n    )\n  }\n","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/restTemplates.ts#L163-L199","documentation":"A 404 HTTPError thrown by update (updateWithoutLock) when no custom REST template document exists for the given restTemplateId, or the doc exists without a _rev (making it un-updatable). The update is refused before any name validation or persistence.","triggerScenarios":"Calling update with a restTemplateId that was deleted, never existed, belongs to another workspace, or references an orphaned doc lacking _rev; also after the template was removed by a concurrent request.","commonSituations":"Client cached a template list that is now stale; template id copy-pasted from a different environment/tenant; the template was deleted while an edit dialog was open; automation referencing a template by hard-coded id after cleanup.","solutions":["Re-fetch the template list and confirm the id still exists before updating","Re-create the template if it was deleted, then apply the update to the new id","Verify the id came from the same workspace/tenant context as the update call","Refresh the client's template cache after any delete so stale ids aren't used"],"exampleFix":"// before\nawait restTemplates.update(restTemplateId, { name, description })\n// after\nconst tpl = (await restTemplates.fetch()).find(t => t.id === restTemplateId)\nif (!tpl) throw new Error(`Template ${restTemplateId} no longer exists`)\nawait restTemplates.update(restTemplateId, { name, description })","handlingStrategy":"validation","validationCode":"const tpl = (await restTemplates.fetch()).find(t => t.id === restTemplateId)\nif (!tpl) throw new Error(`Template ${restTemplateId} not found; cannot update`)","typeGuard":"function templateExists(t: RestTemplate | undefined): t is RestTemplate\n  return !!t && typeof t.id === \"string\"","tryCatchPattern":"try {\n  await restTemplates.update(restTemplateId, { name, description })\n} catch (e) {\n  if (e?.status === 404) {\n    // refresh template list; recreate or inform the user\n    return\n  }\n  throw e\n}","preventionTips":["Refresh the template list after deletes so clients never hold stale ids","Source ids from API responses in the same tenant, never hard-code them","Handle the deleted-while-editing race by re-checking existence before save","Log template ids on failure to spot cross-environment mixups"],"tags":["http-404","rest-templates","stale-data"],"backgroundTag":"resource-not-found-404","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}