Skip to content

Commit

Permalink
test: better formatting dummy route errors
Browse files Browse the repository at this point in the history
  • Loading branch information
matyson committed May 21, 2024
1 parent 387c75d commit a3633c4
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
10 changes: 9 additions & 1 deletion apps/deepsirius-ui/src/components/hello.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import { api } from '~/utils/api';

export default function Hello() {
const { data, isLoading } = api.tbConsumer.hello.useQuery();
const { data, isLoading, isError, error } = api.tbConsumer.hello.useQuery();

if (isLoading) {
return <div>Loading...</div>;
}
if (isError) {
return (
<div>
<div>Error: {error?.message}</div>
<pre>{JSON.stringify(error?.data, null, 2)}</pre>
</div>
);
}

return (
<div className="flex p-4">
Expand Down
30 changes: 22 additions & 8 deletions apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,28 @@ export const tbConsumerRouter = createTRPCRouter({
}),
hello: protectedProcedure.query(async () => {
const url = `${env.TENSORBOARD_API_URL}/api/`;
const res = await fetch(url, {
method: 'GET',
headers: {
'x-api-key': env.TENSORBOARD_API_KEY,
},
});
try {
const res = await fetch(url, {
method: 'GET',
headers: {
'x-api-key': env.TENSORBOARD_API_KEY,
},
});

const data: unknown = await res.json();
return data;
const data: unknown = await res.json();
return data;
} catch (e) {
const error = z
.object({
status: z.string(),
message: z.string(),
})
.parse(e);
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: error.message,
cause: e,
});
}
}),
});

0 comments on commit a3633c4

Please sign in to comment.