{"record":{"id":"1619d61c4b8f1524","repo":"Budibase/budibase","slug":"custom-rest-template-not-found-1619d6","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/api/controllers/restTemplate.ts","lineNumber":151,"sourceCode":"    }),\n  }\n}\n\nexport const destroy = async (\n  ctx: UserCtx<\n    void,\n    DeleteCustomRestTemplateResponse,\n    { restTemplateId: string }\n  >\n) => {\n  const { restTemplateId } = ctx.params\n  if (!isCustomRestTemplateId(restTemplateId)) {\n    throw new HTTPError(\"Invalid custom REST template ID\", 400)\n  }\n\n  const removalResult = await sdk.restTemplates.removeIfUnused(restTemplateId)\n  if (removalResult === \"missing\") {\n    throw new HTTPError(\"Custom REST template not found\", 404)\n  }\n  if (removalResult === \"in_use\") {\n    throw new HTTPError(\n      \"Custom REST template cannot be deleted while it is in use\",\n      409\n    )\n  }\n  ctx.body = {\n    message: `Custom REST template ${restTemplateId} deleted`,\n  }\n}\n","sourceCodeStart":133,"sourceCodeEnd":163,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/restTemplate.ts#L133-L163","documentation":"This 404 HTTPError is returned when sdk.restTemplates.removeIfUnused reports the custom template does not exist. The ID format was valid, but no matching template document was found in the datastore.","triggerScenarios":"DELETE with a well-formed custom template ID that was already deleted, never existed, or belongs to a different app/tenant.","commonSituations":"Double-delete races (two clients deleting the same template); stale IDs cached in the frontend after another user deleted the template; switching apps but reusing old IDs.","solutions":["Re-fetch the template list and confirm the ID still exists before deleting","Handle 404 idempotently in the client (treat as already-deleted success where appropriate)","Retry against the correct app/tenant where the template was created"],"exampleFix":"// before\nawait api.delete(`/api/restTemplates/${staleId}`) // throws 404\n// after\nconst exists = templates.some(t => t.id === id)\nif (exists) await api.delete(`/api/restTemplates/${id}`)","handlingStrategy":"try-catch","validationCode":"const templates = await fetchTemplates()\nconst exists = templates.some(t => t.id === id)\nif (!exists) return // nothing to delete; skip the call","typeGuard":"const templateExists = (templates: { id: string }[], id: string): boolean =>\n  templates.some(t => t.id === id)","tryCatchPattern":"try {\n  await deleteTemplate(id)\n} catch (e) {\n  if (e?.status === 404) {\n    // treat as already deleted; refresh the local list\n  } else throw e\n}","preventionTips":["Handle 404 as idempotent success in delete flows","Refresh the template cache after any delete","Scope IDs to the current app/tenant"],"tags":["http-404","rest-template","not-found","stale-data"],"backgroundTag":"resource-not-found","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}