(response: any, body: any, statusCode?: number)
| 101 | } |
| 102 | |
| 103 | public reply(response: any, body: any, statusCode?: number) { |
| 104 | if (statusCode) { |
| 105 | response.status(statusCode); |
| 106 | } |
| 107 | if (isNil(body)) { |
| 108 | return response.send(); |
| 109 | } |
| 110 | if (body instanceof StreamableFile) { |
| 111 | this.applyStreamHeaders(response, body); |
| 112 | const stream = body.getStream(); |
| 113 | stream.once('error', err => { |
| 114 | body.errorHandler(err, response); |
| 115 | }); |
| 116 | return stream |
| 117 | .pipe<Writable>(response) |
| 118 | .on('error', (err: Error) => body.errorLogger(err)); |
| 119 | } |
| 120 | const responseContentType = response.getHeader('Content-Type'); |
| 121 | if ( |
| 122 | typeof responseContentType === 'string' && |
| 123 | !responseContentType.startsWith('application/json') && |
| 124 | body?.statusCode >= HttpStatus.BAD_REQUEST |
| 125 | ) { |
| 126 | this.logger.warn( |
| 127 | "Content-Type doesn't match Reply body, you might need a custom ExceptionFilter for non-JSON responses", |
| 128 | ); |
| 129 | response.setHeader('Content-Type', 'application/json'); |
| 130 | } |
| 131 | return isObject(body) ? response.json(body) : response.send(String(body)); |
| 132 | } |
| 133 | |
| 134 | public status(response: any, statusCode: number) { |
| 135 | return response.status(statusCode); |
nothing calls this directly
no test coverage detected