Skip to content

hasPostgrestError

hasPostgrestError<T>(response): response is PostgrestResponse<T> & Object

Type guard to check if a PostgrestResponse has an error

Type Parameter
T
ParameterTypeDescription
responsePostgrestResponse<T>The Postgrest response to check

response is PostgrestResponse<T> & Object

true if the response contains an error

const response = await client.from('products').select('*').execute()
if (hasPostgrestError(response)) {
// TypeScript knows: response.error is PostgrestError
console.error('Query failed:', response.error.message)
if (response.error.hint) {
console.log('Hint:', response.error.hint)
}
return
}
// TypeScript knows: response.data is T (not null)
console.log('Found', response.data.length, 'products')