(
req: DaemonRequest,
response: DaemonResponse,
trackArtifact: (opts: { artifactPath: string; tenantId?: string; fileName?: string }) => string,
)
| 8 | import type { DaemonArtifact, DaemonRequest, DaemonResponse, DaemonResponseData } from './types.ts'; |
| 9 | |
| 10 | export function finalizeDaemonResponse( |
| 11 | req: DaemonRequest, |
| 12 | response: DaemonResponse, |
| 13 | trackArtifact: (opts: { artifactPath: string; tenantId?: string; fileName?: string }) => string, |
| 14 | ): DaemonResponse { |
| 15 | const details = getDiagnosticsMeta(); |
| 16 | if (!response.ok) { |
| 17 | emitDiagnostic({ |
| 18 | level: 'error', |
| 19 | phase: 'request_failed', |
| 20 | data: { |
| 21 | code: response.error.code, |
| 22 | message: response.error.message, |
| 23 | }, |
| 24 | }); |
| 25 | const logPathOnFailure = flushDiagnosticsToSessionFile({ force: true }) ?? undefined; |
| 26 | const normalizedError = normalizeError( |
| 27 | new AppError(toAppErrorCode(response.error.code), response.error.message, { |
| 28 | ...(response.error.details ?? {}), |
| 29 | hint: |
| 30 | response.error.hint ?? |
| 31 | (typeof response.error.details?.hint === 'string' |
| 32 | ? response.error.details.hint |
| 33 | : undefined), |
| 34 | diagnosticId: response.error.diagnosticId, |
| 35 | logPath: response.error.logPath, |
| 36 | }), |
| 37 | { |
| 38 | diagnosticId: details.diagnosticId, |
| 39 | logPath: logPathOnFailure, |
| 40 | }, |
| 41 | ); |
| 42 | return { ok: false, error: normalizedError }; |
| 43 | } |
| 44 | emitDiagnostic({ level: 'info', phase: 'request_success' }); |
| 45 | flushDiagnosticsToSessionFile(); |
| 46 | return { |
| 47 | ok: true, |
| 48 | data: registerDownloadableArtifacts(req, response.data, trackArtifact), |
| 49 | }; |
| 50 | } |
| 51 | |
| 52 | function registerDownloadableArtifacts( |
| 53 | req: DaemonRequest, |
no test coverage detected