Skip to content

Commit

Permalink
fix(route.ts): add console.error to log errors that occur while proce…
Browse files Browse the repository at this point in the history
…ssing response

fix(NoData.tsx): remove unused state and useEffect, create new Notifier instance inside sendTestException function
feat(NoData.tsx): add support for sending test exception to Airbrake to verify integration
fix(AI.tsx): add console.log to log errors that occur when connection is closed due to an error
  • Loading branch information
masterkain committed May 22, 2023
1 parent 320fdb7 commit 9e7b49d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
3 changes: 1 addition & 2 deletions app/api/ai/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export async function GET(request: NextRequest) {

responsePromise
.catch(async (error) => {
console.error('An error occurred while processing the response:', error);
const errorMessage = `An error occurred: ${error.message}\n\n`;
const data = new TextEncoder().encode(`data: ${errorMessage}`);
await writer.write(data);
Expand All @@ -85,8 +86,6 @@ export async function GET(request: NextRequest) {
}
});



return new Response(readable, {
headers: {
'Content-Type': 'text/event-stream',
Expand Down
35 changes: 14 additions & 21 deletions components/NoData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,27 @@
import { Notifier } from '@airbrake/browser';
import { project } from '@prisma/client';
import { useRouter } from 'next/navigation';
import { useEffect, useState, useTransition } from 'react';
import { useTransition } from 'react';
import { SlCheck, SlDisc, SlEnergy } from 'react-icons/sl';

export default function NoData({ project }: { project: project }) {
const [isPending, startTransition] = useTransition();
const { refresh } = useRouter();
const [airbrake, setAirbrake] = useState<Notifier | null>(null);

useEffect(() => {
setAirbrake(
new Notifier({
projectId: 1,
projectKey: project.api_key,
environment: 'test',
host: window.location.origin,
remoteConfig: false,
performanceStats: false,
queryStats: false,
queueStats: false,
})
);
}, [project.api_key]);

const sendTestException = async () => {
if (airbrake) {
await airbrake.notify(new Error('This is a test exception from Airbroke'));
startTransition(() => refresh());
}
const airbrake = new Notifier({
projectId: 1,
projectKey: project.api_key,
environment: 'test',
host: window.location.origin,
remoteConfig: false,
performanceStats: false,
queryStats: false,
queueStats: false,
});

await airbrake.notify(new Error('This is a test exception from Airbroke'));
startTransition(() => refresh());
};

return (
Expand Down
2 changes: 1 addition & 1 deletion components/occurrence/toolbox/AI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ToolboxAI({ occurrenceId }: { occurrenceId: bigint }) {
};

eventSource.onerror = (event) => {
console.log('Connection was closed');
console.log('Connection was closed due to an error:', event);
setIsStarted(false);
eventSource.close();
};
Expand Down

0 comments on commit 9e7b49d

Please sign in to comment.