| 6 | * @returns {Response} API response |
| 7 | */ |
| 8 | export async function selectDataSource(c, dbLogic, mockLogic) { |
| 9 | try { |
| 10 | // Use mock data if database is not available |
| 11 | if (!c.env.DB_AVAILABLE) { |
| 12 | return await mockLogic(c); |
| 13 | } |
| 14 | |
| 15 | // Use database if available |
| 16 | return await dbLogic(c); |
| 17 | } catch (e) { |
| 18 | console.error("API Error:", e); |
| 19 | return Response.json( |
| 20 | { error: e instanceof Error ? e.message : e }, |
| 21 | { status: 500 }, |
| 22 | ); |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Contains mock data logic functions for book-related endpoints |