Budibase/budibase · error · HTTPError

Custom REST template not found

Error message

Custom REST template not found

What it means

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.

Source

Thrown at packages/server/src/api/controllers/restTemplate.ts:151

    }),
  }
}

export const destroy = async (
  ctx: UserCtx<
    void,
    DeleteCustomRestTemplateResponse,
    { restTemplateId: string }
  >
) => {
  const { restTemplateId } = ctx.params
  if (!isCustomRestTemplateId(restTemplateId)) {
    throw new HTTPError("Invalid custom REST template ID", 400)
  }

  const removalResult = await sdk.restTemplates.removeIfUnused(restTemplateId)
  if (removalResult === "missing") {
    throw new HTTPError("Custom REST template not found", 404)
  }
  if (removalResult === "in_use") {
    throw new HTTPError(
      "Custom REST template cannot be deleted while it is in use",
      409
    )
  }
  ctx.body = {
    message: `Custom REST template ${restTemplateId} deleted`,
  }
}

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Re-fetch the template list and confirm the ID still exists before deleting
  2. Handle 404 idempotently in the client (treat as already-deleted success where appropriate)
  3. Retry against the correct app/tenant where the template was created

Example fix

// before
await api.delete(`/api/restTemplates/${staleId}`) // throws 404
// after
const exists = templates.some(t => t.id === id)
if (exists) await api.delete(`/api/restTemplates/${id}`)
Defensive patterns

Strategy: try-catch

Validate before calling

const templates = await fetchTemplates()
const exists = templates.some(t => t.id === id)
if (!exists) return // nothing to delete; skip the call

Type guard

const templateExists = (templates: { id: string }[], id: string): boolean =>
  templates.some(t => t.id === id)

Try / catch

try {
  await deleteTemplate(id)
} catch (e) {
  if (e?.status === 404) {
    // treat as already deleted; refresh the local list
  } else throw e
}

Prevention

When it happens

Trigger: DELETE with a well-formed custom template ID that was already deleted, never existed, or belongs to a different app/tenant.

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

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/1619d61c4b8f1524. Report an issue: GitHub.