Skip to content

Commit

Permalink
test: try to catch consumer fetch error
Browse files Browse the repository at this point in the history
  • Loading branch information
matyson committed May 20, 2024
1 parent f2c3005 commit 0c7e640
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions apps/deepsirius-ui/src/server/api/routers/tb_consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,37 @@ export const tbConsumerRouter = createTRPCRouter({
)
.query(async ({ input }) => {
const url = `${env.TENSORBOARD_API_URL}/api/tensorboard/start`;
console.log(url);

const res = await fetch(url, {
method: 'POST',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'X-API-KEY': env.TENSORBOARD_API_KEY,
},
body: JSON.stringify(input),
});

console.log(res);

const data: unknown = await res.json();
console.log(data);

if (!res.ok) {
const error = z
.object({
status: z.string(),
message: z.string(),
})
.parse(data);

throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: error.message,
try {
const res = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-KEY': env.TENSORBOARD_API_KEY,
},
body: JSON.stringify(input),
});
}

const parsed = TensorboardResponseSchema.parse(data);

return parsed;
const data: unknown = await res.json();

if (!res.ok) {
const error = z
.object({
status: z.string(),
message: z.string(),
})
.parse(data);

throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: error.message,
});
}
const parsed = TensorboardResponseSchema.parse(data);

return parsed;
} catch (e) {
console.log(e);
}
}),
});

0 comments on commit 0c7e640

Please sign in to comment.