(options: StandardHandlerOptions<T>)
| 63 | } |
| 64 | |
| 65 | init(options: StandardHandlerOptions<T>): void { |
| 66 | options.rootInterceptors ??= [] |
| 67 | options.interceptors ??= [] |
| 68 | options.clientInterceptors ??= [] |
| 69 | |
| 70 | options.rootInterceptors.unshift(async (interceptorOptions) => { |
| 71 | const logger = ( |
| 72 | (interceptorOptions.context as LoggerContext)[CONTEXT_LOGGER_SYMBOL] ?? this.logger |
| 73 | ).child({ |
| 74 | rpc: { id: this.generateId(interceptorOptions), system: ORPC_NAME }, |
| 75 | }) |
| 76 | |
| 77 | /** |
| 78 | * pino-http might have already set req info in bindings |
| 79 | */ |
| 80 | if (!logger.bindings().req) { |
| 81 | logger.setBindings({ |
| 82 | req: { |
| 83 | url: interceptorOptions.request.url, |
| 84 | method: interceptorOptions.request.method, |
| 85 | headers: { |
| 86 | 'content-type': interceptorOptions.request.headers['content-type'], |
| 87 | 'content-length': interceptorOptions.request.headers['content-length'], |
| 88 | 'content-disposition': interceptorOptions.request.headers['content-disposition'], |
| 89 | }, |
| 90 | }, |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | if (this.logRequestAbort) { |
| 95 | const signal = interceptorOptions.request.signal |
| 96 | |
| 97 | if (signal?.aborted) { |
| 98 | logger?.info(`request was aborted before handling (${String(signal.reason)})`) |
| 99 | } |
| 100 | else { |
| 101 | signal?.addEventListener('abort', () => { |
| 102 | logger?.info(`request is aborted (${String(signal.reason)})`) |
| 103 | }, { once: true }) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | try { |
| 108 | if (this.logRequestResponse) { |
| 109 | logger?.info('request received') |
| 110 | } |
| 111 | |
| 112 | const result = await interceptorOptions.next({ |
| 113 | ...interceptorOptions, |
| 114 | context: { |
| 115 | ...interceptorOptions.context, |
| 116 | [CONTEXT_LOGGER_SYMBOL]: logger, |
| 117 | }, |
| 118 | }) |
| 119 | |
| 120 | if (this.logRequestResponse) { |
| 121 | if (result.matched) { |
| 122 | logger?.info({ |
nothing calls this directly
no test coverage detected