Skip to content

Commit

Permalink
Catch errors from search results that don't return results and turn t…
Browse files Browse the repository at this point in the history
…hem into 200s
  • Loading branch information
aaronbrethorst committed Aug 24, 2024
1 parent ed0210b commit eee9096
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/routes/api/oba/search/+server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ export async function GET({ url }) {
const searchInput = url.searchParams.get('query');

try {
console.log('Search input:', searchInput);

const routeResponse = await oba.searchForRoute.retrieve({ input: searchInput });

console.log('Route Response:', routeResponse);

return new Response(JSON.stringify(routeResponse), {
const response = await oba.searchForRoute.retrieve({ input: searchInput });
return new Response(JSON.stringify(response), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} catch (error) {
console.error('Search error:', error);

return new Response(JSON.stringify({ error: 'Search failed', details: error.message }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
if (error.error.code == 404) {
return new Response(JSON.stringify({ error: 'No results found' }), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} else {
return new Response(JSON.stringify({ error: 'Search failed', details: error.message }), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
}
}

0 comments on commit eee9096

Please sign in to comment.