Skip to content

Commit

Permalink
fix: address issue where user would see a 500 if indexing a tool that…
Browse files Browse the repository at this point in the history
… does not exist

Signed-off-by: tylerslaton <[email protected]>
  • Loading branch information
tylerslaton committed Mar 13, 2024
1 parent f458bff commit d3e47b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,21 @@ export const upsertToolForUrl = async (url: string, tools: Tool[], examples: Too
};
}

export const removeToolForUrl = async (url: string): Promise<Tool[]> => {
const toolEntry = await prisma.toolEntry.delete({
export const removeToolForUrlIfExists = async (url: string): Promise<Tool[]> => {
const toolEntry = await prisma.toolEntry.findFirst({
where: {
url: url
}
});
if (!toolEntry) {
return [];
}
await prisma.toolEntry.delete({
where: {
url: url
}
});
return toolEntry.content as Tool[];
return JSON.parse(toolEntry.content as string) as Tool[];
}

export const getToolsForQuery = async (query: string): Promise<Record<string, Tool[]>> => {
Expand Down
2 changes: 1 addition & 1 deletion src/server/api/[...slug].post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default defineEventHandler(async (event) => {
if (!toolResponse.ok) {
// clean-up any existing tools if the tool.gpt file is no longer found or is private
if (toolResponse.status === 404 || toolResponse.status === 403) {
await db.removeToolForUrl(url);
await db.removeToolForUrlIfExists(url);
}
throw createError({
statusCode: toolResponse.status,
Expand Down

0 comments on commit d3e47b7

Please sign in to comment.