读取错误详情
向本地 Flight 服务器请求不存在的 demo/missing 表。使用 FlightCallOptions.onTrailer 保存调用的尾部元数据。PyArrow 在 grpc-status-details-bin 字段中发送 FlightError.extra_info 的字节。Arrow 传输实现
error-details.ts
import { FlightClient, pathDescriptor } from 'arrow-flight-client';
import type { FlightResponseMetadata } from 'arrow-flight-client';
async function main() {
const client = new FlightClient('127.0.0.1:8815');
let trailer: FlightResponseMetadata | undefined;
try {
await client.getFlightInfo(pathDescriptor('demo', 'missing'), {
onTrailer: (metadata) => {
trailer = metadata;
}
});
}
catch (error) {
const extraInfo = trailer?.['grpc-status-details-bin']?.[0];
if (extraInfo instanceof Uint8Array) {
console.error('Flight extra_info:', Buffer.from(extraInfo).toString('utf8'));
}
throw error;
}
finally {
await client.close();
}
}
await main();
RPC 完成时,onTrailer 会收到字符串或字节的数组。请按照服务器使用的格式处理字节。示例将其解码为 UTF-8 文本,并继续传递包含 code 和 details 的错误。如果调用在服务器响应之前失败,尾部元数据可能不存在。