Correct error handling, specify auth mode as api key

This commit is contained in:
Theodore Li
2026-02-12 15:26:13 -08:00
parent 6c006cdfec
commit fc97ce007d
3 changed files with 14 additions and 0 deletions

View File

@@ -1,10 +1,12 @@
import { GoogleBooksIcon } from '@/components/icons'
import type { BlockConfig } from '@/blocks/types'
import { AuthMode } from '@/blocks/types'
export const GoogleBooksBlock: BlockConfig = {
type: 'google_books',
name: 'Google Books',
description: 'Search and retrieve book information',
authMode: AuthMode.ApiKey,
longDescription:
'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.',
docsLink: 'https://docs.sim.ai/tools/google_books',
@@ -120,6 +122,7 @@ export const GoogleBooksBlock: BlockConfig = {
{ label: 'Lite', id: 'lite' },
],
value: () => 'full',
condition: { field: 'operation', value: 'volume_details' },
mode: 'advanced',
},
],

View File

@@ -29,6 +29,9 @@ interface GoogleBooksVolumeResponse {
identifier: string
}>
}
error?: {
message?: string
}
}
export const googleBooksVolumeDetailsTool: ToolConfig<
@@ -81,6 +84,10 @@ export const googleBooksVolumeDetailsTool: ToolConfig<
transformResponse: async (response: Response) => {
const data: GoogleBooksVolumeResponse = await response.json()
if (data.error) {
throw new Error(`Google Books API error: ${data.error.message || 'Unknown error'}`)
}
if (!data.volumeInfo) {
throw new Error('Volume not found')
}

View File

@@ -155,6 +155,10 @@ export const googleBooksVolumeSearchTool: ToolConfig<
transformResponse: async (response: Response) => {
const data = await response.json()
if (data.error) {
throw new Error(`Google Books API error: ${data.error.message || 'Unknown error'}`)
}
const items: GoogleBooksVolumeItem[] = data.items ?? []
const volumes = items.map(extractVolumeInfo)