-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Error Handling | ||
|
||
Farcaster Frames have the ability to return application-level error messages (see the [spec](https://warpcast.notion.site/Frames-Errors-ddc965b097d44d9ea03ddf98498597c6)). This is the best way for frame developers to give users feedback in response to an input or other requirements. | ||
|
||
## Overview | ||
|
||
At a glance: | ||
|
||
1. A Frame has a `<Button>{:jsx}` | ||
2. When the user presses the button in the App, the App will make a `POST` request to the specified route. | ||
3. The App responds with a `400` status code and error message. | ||
4. The client displays the error message to the user. | ||
|
||
Frog supports error messages for [frames](/reference/frog-frame-context#error), [transactions](/reference/frog-transaction-context#error), and [cast actions](/reference/frog-cast-action-context#error). | ||
|
||
## Reference | ||
|
||
:::code-group | ||
```ts twoslash [Frame Error] | ||
// @noErrors | ||
/** @jsxImportSource frog/jsx */ | ||
// ---cut--- | ||
import { Frog } from 'frog' | ||
|
||
export const app = new Frog() | ||
|
||
app.frame('/', (c) => { | ||
return c.error({/* ... */}) | ||
}) | ||
``` | ||
```ts twoslash [Transaction Error] | ||
// @noErrors | ||
/** @jsxImportSource frog/jsx */ | ||
// ---cut--- | ||
import { Frog } from 'frog' | ||
|
||
export const app = new Frog() | ||
|
||
app.transaction('/', (c) => { | ||
return c.error({/* ... */}) | ||
}) | ||
``` | ||
```ts twoslash [Cast Action Error] | ||
// @noErrors | ||
/** @jsxImportSource frog/jsx */ | ||
// ---cut--- | ||
import { Frog } from 'frog' | ||
|
||
export const app = new Frog() | ||
|
||
app.castAction('/', (c) => { | ||
return c.error({/* ... */}) | ||
}) | ||
``` | ||
::: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { expect, test } from 'vitest' | ||
|
||
import { resolveUnitToken } from './Box.js' | ||
import { defaultVars } from './vars.js' | ||
|
||
test('resolveUnitToken', () => { | ||
const { units } = defaultVars | ||
|
||
const vheight = 630 | ||
|
||
// 1.91:1 | ||
{ | ||
const vwidth = 1_200 | ||
const vmax = Math.max(vwidth, vheight) | ||
const res = resolveUnitToken(units, 16, vmax) | ||
expect(res).toMatchInlineSnapshot(`"30.476190476190474px"`) | ||
} | ||
|
||
// 1:1 | ||
{ | ||
const vwidth = 630 | ||
const vmax = Math.max(vwidth, vheight) | ||
const res = resolveUnitToken(units, 16, vmax) | ||
expect(res).toMatchInlineSnapshot(`"16px"`) | ||
} | ||
}) |