Skip to content

Commit ce7b9d1

Browse files
committed
Add toast on error
1 parent 489222a commit ce7b9d1

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

package-lock.json

+35-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"react": "17.0.2",
1919
"react-dom": "17.0.2",
2020
"react-hot-toast": "^2.1.1",
21-
"react-simple-code-editor": "^0.11.0"
21+
"react-simple-code-editor": "^0.11.0",
22+
"react-toastify": "^8.1.0"
2223
},
2324
"devDependencies": {
2425
"@types/prismjs": "^1.16.6",

pages/index.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Image from 'next/image';
44
import Script from 'next/script';
55
import Link from 'next/link';
66
import axios from 'axios';
7+
import { ToastContainer, toast } from 'react-toastify';
78
import {
89
Menu, Transition, Disclosure, Switch,
910
} from '@headlessui/react';
@@ -17,6 +18,7 @@ import Output from '../components/Output';
1718
import vscode from '../assets/vsc.svg';
1819
import logo from '../assets/mintlify.svg';
1920
import EXAMPLES from '../content/examples';
21+
import 'react-toastify/dist/ReactToastify.css';
2022

2123
const ENDPOINT = process.env.NODE_ENV === 'development'
2224
? 'http://localhost:5000'
@@ -161,8 +163,8 @@ export default function Example() {
161163

162164
setOutputDisplay(docstring);
163165
} catch (error: any) {
164-
const errorMessage = error.response?.data.error || 'An enexpected error occurred';
165-
console.log({ errorMessage });
166+
const errorMessage = error?.response?.data?.error || 'An enexpected error occurred';
167+
toast(errorMessage);
166168
} finally {
167169
setIsGenerating(false);
168170
}
@@ -574,6 +576,7 @@ export default function Example() {
574576
</p>
575577
</div>
576578
</footer>
579+
<ToastContainer position="bottom-right" />
577580
<Script>
578581
{`// Initialize the agent at application startup.
579582
fpPromise = new Promise((resolve, reject) => {

0 commit comments

Comments
 (0)