-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add error handing and replace api
- Loading branch information
Showing
10 changed files
with
48 additions
and
26 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
File renamed without changes.
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
File renamed without changes.
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,23 @@ | ||
'use client' | ||
|
||
import React from 'react' | ||
|
||
import { Button } from '@/components/ui/button' | ||
|
||
export default function Error({ error, reset }: any) { | ||
React.useEffect(() => { | ||
console.log('logging error:', error) | ||
}, [error]) | ||
|
||
return ( | ||
<div> | ||
<div className="space-y-4"> | ||
<h2 className="text-lg font-bold">Error</h2> | ||
<p className="text-sm text-red-900">{error?.message}</p> | ||
<div> | ||
<Button onClick={() => reset()}>Try Again</Button> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} |
37 changes: 18 additions & 19 deletions
37
app/loading-and-streaming/_components/prompt-activity.tsx
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 |
---|---|---|
@@ -1,41 +1,40 @@ | ||
import { logger } from '@/lib/shared' | ||
import { sleep } from '@/lib/utils' | ||
|
||
interface Activity { | ||
activity: string | ||
type: string | ||
participants: number | ||
price: number | ||
link: string | ||
key: string | ||
accessibility: number | ||
interface Joke { | ||
categories: [] | ||
created_at: string | ||
icon_url: string | ||
id: string | ||
updated_at: string | ||
url: string | ||
value: string | ||
} | ||
async function getActivity(): Promise<Activity> { | ||
logger.info('getActivity start') | ||
const res = await fetch('https://www.boredapi.com/api/activity', { | ||
async function getRandomJoke(): Promise<Joke> { | ||
logger.info('getRandomJoke start') | ||
const res = await fetch('https://api.chucknorris.io/jokes/random', { | ||
cache: 'no-store', | ||
}) | ||
await sleep(1500) | ||
logger.info(res, 'getActivity done') | ||
logger.info(res, 'getRandomJoke done') | ||
|
||
if (!res.ok) { | ||
// This will activate the closest `error.js` Error Boundary | ||
const e = new Error('Failed to getActivity') | ||
const e = new Error('Failed to getRandomJoke') | ||
logger.error(e) | ||
throw e | ||
} | ||
|
||
return res.json() | ||
} | ||
export const PromptActivity = async () => { | ||
const data = await getActivity() | ||
const data = await getRandomJoke() | ||
return ( | ||
<div> | ||
<h2>Activity: </h2> | ||
<h4>desc: {data.activity}</h4> | ||
<p>price: {data.price}</p> | ||
<p>participants {data.participants}</p> | ||
<p>accessibility {data.accessibility}</p> | ||
<h2>Random Joke: </h2> | ||
<h4>url: {data.url}</h4> | ||
<p>updated_at: {data.updated_at}</p> | ||
<p>{data.value}</p> | ||
</div> | ||
) | ||
} |
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
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