Line data Source code
1 : import { LoggableException } from "./logger/logger.js";
2 :
3 : export interface ChannelTlsSettings {
4 : /// The mTLS client key path
5 : keyPath?: string;
6 : /// The mTLS client certificate path
7 : pubPath?: string;
8 : /// The mTLS ca certificates path
9 : caPath?: string;
10 : }
11 :
12 : export interface ChannelArgs {
13 : /// The endpoint url
14 : endpoint: string,
15 : /// The channel tls settings
16 : tls?: ChannelTlsSettings;
17 : }
18 :
19 : export interface RawProxyError {
20 : /// The error
21 : message: string;
22 : /// Error data produced by TypeScript proxy clients.
23 : data?: Record<string, string>;
24 : /// Error data produced by the native Rust proxy.
25 : details?: Record<string, string>;
26 : }
27 :
28 1 : export function getProxyErrorData(error: RawProxyError): Record<string, string> {
29 1 : return error.data ?? error.details ?? {};
30 1 : }
31 :
32 1 : export class ChannelError extends LoggableException {
33 : /// The status code
34 1 : statusCode: number;
35 : /// The response headers
36 1 : headers: Headers | null;
37 :
38 1 : constructor(error: RawProxyError, status: number, headers?: Headers, target?: string) {
39 1 : super(error.message, getProxyErrorData(error), target);
40 1 : this.statusCode = status;
41 1 : this.headers = headers ?? null;
42 1 : }
43 1 : }
44 :
45 : export interface ChannelMetadataProvider {
46 : /// Get additional request metadata.
47 : /// Retrieving the request metadata might involve refreshing the OAuth token, thus the promise.
48 : getRequestMetadata(): Promise<Record<string, string>>;
49 : }
|