Skip to content

Commit fc97ce0

Browse files
author
Theodore Li
committed
Correct error handling, specify auth mode as api key
1 parent 6c006cd commit fc97ce0

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

apps/sim/blocks/blocks/google_books.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { GoogleBooksIcon } from '@/components/icons'
22
import type { BlockConfig } from '@/blocks/types'
3+
import { AuthMode } from '@/blocks/types'
34

45
export const GoogleBooksBlock: BlockConfig = {
56
type: 'google_books',
67
name: 'Google Books',
78
description: 'Search and retrieve book information',
9+
authMode: AuthMode.ApiKey,
810
longDescription:
911
'Search for books using the Google Books API. Find volumes by title, author, ISBN, or keywords, and retrieve detailed information about specific books including descriptions, ratings, and publication details.',
1012
docsLink: 'https://docs.sim.ai/tools/google_books',
@@ -120,6 +122,7 @@ export const GoogleBooksBlock: BlockConfig = {
120122
{ label: 'Lite', id: 'lite' },
121123
],
122124
value: () => 'full',
125+
condition: { field: 'operation', value: 'volume_details' },
123126
mode: 'advanced',
124127
},
125128
],

apps/sim/tools/google_books/volume_details.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ interface GoogleBooksVolumeResponse {
2929
identifier: string
3030
}>
3131
}
32+
error?: {
33+
message?: string
34+
}
3235
}
3336

3437
export const googleBooksVolumeDetailsTool: ToolConfig<
@@ -81,6 +84,10 @@ export const googleBooksVolumeDetailsTool: ToolConfig<
8184
transformResponse: async (response: Response) => {
8285
const data: GoogleBooksVolumeResponse = await response.json()
8386

87+
if (data.error) {
88+
throw new Error(`Google Books API error: ${data.error.message || 'Unknown error'}`)
89+
}
90+
8491
if (!data.volumeInfo) {
8592
throw new Error('Volume not found')
8693
}

apps/sim/tools/google_books/volume_search.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export const googleBooksVolumeSearchTool: ToolConfig<
155155
transformResponse: async (response: Response) => {
156156
const data = await response.json()
157157

158+
if (data.error) {
159+
throw new Error(`Google Books API error: ${data.error.message || 'Unknown error'}`)
160+
}
161+
158162
const items: GoogleBooksVolumeItem[] = data.items ?? []
159163
const volumes = items.map(extractVolumeInfo)
160164

0 commit comments

Comments
 (0)