( response: Response, functionType: 'query' | 'mutation' | 'action' | 'function' )
| 85 | * @see https://docs.convex.dev/http-api/#post-apiquery-apimutation-apiaction |
| 86 | */ |
| 87 | export async function transformFunctionCallResponse( |
| 88 | response: Response, |
| 89 | functionType: 'query' | 'mutation' | 'action' | 'function' |
| 90 | ): Promise<ConvexFunctionCallResponse> { |
| 91 | const data = (await parseConvexResponse(response)) as ConvexFunctionCallApiResponse |
| 92 | |
| 93 | if (data.status === 'error') { |
| 94 | const details = |
| 95 | data.errorData !== undefined && data.errorData !== null |
| 96 | ? ` (${JSON.stringify(data.errorData)})` |
| 97 | : '' |
| 98 | throw new Error( |
| 99 | `Convex ${functionType} failed: ${data.errorMessage || 'Unknown error'}${details}` |
| 100 | ) |
| 101 | } |
| 102 | |
| 103 | return { |
| 104 | success: true, |
| 105 | output: { |
| 106 | value: data.value ?? null, |
| 107 | logLines: data.logLines ?? [], |
| 108 | }, |
| 109 | } |
| 110 | } |
no test coverage detected