mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-13 07:55:09 -05:00
Correct error handling, specify auth mode as api key
This commit is contained in:
@@ -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',
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user