Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions sdks/database.do/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ class CollectionHandler<T = CollectionData> implements CollectionMethods<T> {
try {
return await this.api.getById<T>(this.collection, id)
} catch (error) {
const err = error as { status?: number; statusCode?: number }
if (err.status === 404 || err.statusCode === 404) {
try {
const response = await fetch(`https://database.do/${id}`)

if (response.ok) {
return await response.json() as T
}
} catch (fetchError) {
console.error('Failed to trigger generation:', fetchError)
}
}
return handleApiError(error, 'findOne', this.collection)
}
}
Expand Down Expand Up @@ -240,6 +252,18 @@ export class DatabaseClient {
const collectionName = collection === 'resources' ? 'things' : collection
return await this.api.getById<T>(collectionName, id)
} catch (error) {
const err = error as { status?: number; statusCode?: number }
if (err.status === 404 || err.statusCode === 404) {
try {
const response = await fetch(`https://database.do/${id}`)

if (response.ok) {
return await response.json() as T
}
} catch (fetchError) {
console.error('Failed to trigger generation:', fetchError)
}
}
return handleApiError(error, 'findOne', collection)
}
}
Expand Down