Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
brnovasco committed May 21, 2024
2 parents c2b43f5 + ecea0db commit 764beec
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
23 changes: 23 additions & 0 deletions apps/deepsirius-ui/src/components/hello.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { api } from '~/utils/api';

export default function Hello() {
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">
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
);
}
18 changes: 6 additions & 12 deletions apps/deepsirius-ui/src/pages/hello.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
import { api } from '~/utils/api';
import dynamic from 'next/dynamic';

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

if (isLoading) {
return <div>Loading...</div>;
}
const Hello = dynamic(() => import('~/components/hello'), {
ssr: false,
});

return (
<div className="flex p-4">
<pre>{JSON.stringify(data, null, 2)}</pre>
</div>
);
export default function Page() {
return <Hello />;
}
29 changes: 20 additions & 9 deletions apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export const tbConsumerRouter = createTRPCRouter({
.object({
status: z.string(),
message: z.string(),

})
.parse(data);

throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: error.message,
cause: data,
});
}
const parsed = TensorboardResponseSchema.parse(data);
Expand All @@ -50,14 +52,23 @@ 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,
},
});

const data: unknown = await res.json();
return data;
try {
const res = await fetch(url, {
method: 'GET',
headers: {
'x-api-key': env.TENSORBOARD_API_KEY,
},
});

const data: unknown = await res.json();
return data;
} catch (e) {
console.log('OLHA ESSE ERRO PLMDDS', e);
throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: 'Failed to fetch Tensorboard API',
cause: e,
});
}
}),
});

0 comments on commit 764beec

Please sign in to comment.