When a question cannot be answered, ask resolves false, the table stays as it was, and the hook's error is a GridsayError. Show error.message to your user; read code to decide what to do next.
Sort the tickets by priority, most urgent first
The Priority column can't be sorted in this grid.
Your user reads this sentence. The table stays as it was.make a chart of orders by country
Charts are turned off for this grid, so I can't create one.
Your user reads this sentence. The table stays as it was.import type { GridsayError } from '@gridsay/tanstack-table/react'; type Props = { error: GridsayError | null; signInUrl: string };export function AssistantError({ error, signInUrl }: Props) { if (!error) return null; const code = error.code; if (code === 'reset') return null; let next = 'Try again later. Contact the app owner if this continues.'; switch (code) { case 'unauthenticated_user': return <p role="alert">{error.message} <a href={signInUrl}>Sign in</a></p>; case 'query_not_understood': next = 'Try asking for a filter, a sort, a group or the first rows selected.'; break; case 'rate_limited': next = error.retryAfter === undefined ? 'Wait before asking again.' : `Wait ${error.retryAfter} seconds before asking again.`; break; case 'invalid_request': next = 'Check the question and its length.'; break; case 'context_too_large': next = 'This table needs a smaller description. Contact the app owner.'; break; case 'quota_exceeded': case 'billing_limit_exceeded': case 'invalid_api_key': case 'origin_not_allowed': case 'forbidden': case 'cannot_apply': case 'unexpected_error': case 'invalid_answer': case 'not_json': case 'not_found': next = 'The app owner needs to check this assistant.'; break; case 'connection_failed': next = 'Check your connection before submitting again.'; break; case 'upstream_unavailable': case 'internal_error': break; } return <div role="alert"><p>{error.message}</p><p>{next}</p></div>;}Put <AssistantError error={error} signInUrl="/sign-in" /> under your question box, with your app's sign-in address. Keep the question in the box when ask returns false, so the user can reword it. Compare codes, never messages: the messages may change.
A declined question comes back as status 422, code query_not_understood. Its message is one short sentence from the assistant, in the user's language, saying what it cannot do. The sentence varies with the question, so do not match it in code.
When the model's answer uses something the table has switched off, Gridsay first asks the model to correct it, and a refusal then comes in the model's own words. Only if the corrected answer still uses it, or the correction call fails, does the user see a fixed sentence:
| The answer needs | The user sees |
|---|---|
| Totals | "Totals are switched off for this table." |
| A pivot | "Pivoting is switched off for this table." |
| A chart | "This table has no chart." |
| Filtering, on a table without it | "Filtering is switched off for this table." |
| Sorting, on a table without it | "Sorting is switched off for this table." |
| Grouping, on a table without it | "Grouping is switched off for this table." |
| Selection, on a table without it | "Selection is switched off for this table." |
| A column that cannot be used that way | "The `status` column can't be sorted.", with the column's id, and "filtered" or "grouped" |
The plugin reports totals, pivots and charts as switched off on every TanStack Table. If none of these applies and the answer still cannot be used, the user sees "I couldn't apply that request to this table. Try rephrasing it."
What your route receives from Gridsay for a declined question:
{ "ok": false, "code": "query_not_understood", "statusCode": 422, "message": "Cannot delete rows.", "detail": "The question could not be applied to this table. Check the columns and enabled features sent by your resolver. Request example-request-id; find it at /app/usage."}detail is for you, never for your users. Its request id finds the question on the dashboard's Usage page. The whole envelope is in the HTTP API reference.
From Gridsay, through your route:
| Status | code | Cause | Charged |
|---|---|---|---|
| 400 | invalid_request | The request could not be read: an empty or overlong question, or a bad option. detail names the field. | No |
| 401 | invalid_api_key | The key is missing, disabled, expired or not recognised. | No |
| 401 | unauthenticated_user | Your route turned the caller away, or Gridsay did not accept the end user's token. | No |
| 402 | quota_exceeded | No plan in force, a trial that has ended or cannot cover the question, a blocked account or an overdue payment. | No |
| 402 | billing_limit_exceeded | The month's credits and extra-usage cap cannot cover the question. | No |
| 403 | origin_not_allowed | The page's origin is not on the publishable key's list. | No |
| 403 | forbidden | The publishable key has no way to identify end users set up. | No |
| 404 | not_found | Wrong address. | No |
| 413 | context_too_large | The question, columns, options and state are over a size limit. | No |
| 422 | query_not_understood | The assistant declined the question. | Yes |
| 429 | rate_limited | A limit on your key or your user was reached, too many questions are in progress, or too many recent questions failed. Wait retryAfter seconds. | No |
| 502 | upstream_unavailable | The model failed or its answer was unusable. | No |
| 503 | upstream_unavailable | The service could not take the question. | No |
| 500 | internal_error | Something failed on our side. Check Usage before sending again. If it repeats, contact us with the time. | Maybe. The question may already have been charged. |
From the plugin itself:
code | Cause | Charged |
|---|---|---|
unauthenticated_user | getToken returned nothing or threw. No request was sent, and there is no status. | No |
unexpected_error | Your headers function, or the table while it was read, threw. cause holds it. Nothing was sent. | No |
connection_failed | The request did not complete. Gridsay may or may not have answered. | Unknown |
not_json | Your route answered with something that is not JSON, often a missing route or a sign-in page. status says which. | Depends on what your route did |
invalid_answer | The response was not an answer the plugin can read. Return Gridsay's body and status unchanged. | Depends on what your route did |
cannot_apply | Gridsay answered, but the table could not take the answer. detail names what, such as sorting: no column "total". | Yes |
reset | reset() was called while the question waited. The hook does not set error for it. | The request may already be charged |
A route can also fail with its own message and no code, as the quickstart's route does when its environment is not set. Then error.code is undefined: show the message.
cannot_apply means the table did not match what it told Gridsay: a column id changed, a feature is missing, or a controlled state handler did not take the answer within one second. Nothing stays applied, or the earlier state is put back. The question was answered, so it is charged: fix the table before asking again, and do not retry in a loop. See Controlled state.
cannot_apply) is charged, because Gridsay answered.reset() does not cancel or refund a request already sent.What a question costs by tier: Tiers and credits. Every code across Gridsay's endpoints: Errors.