| 93 | }; |
| 94 | |
| 95 | const handleGenerateError = (c: any, error: unknown) => { |
| 96 | if (error instanceof ApiErrorZod) { |
| 97 | throw error; |
| 98 | } |
| 99 | |
| 100 | const errorMessage = |
| 101 | error instanceof Error |
| 102 | ? error.message |
| 103 | : 'Unexpected error occurred in /pipe/v1/run'; |
| 104 | |
| 105 | dlog('Error /pipe/v1/run.ts:', error); |
| 106 | |
| 107 | throw new ApiError({ |
| 108 | status: error instanceof ApiError ? error.status : 500, |
| 109 | code: error instanceof ApiError ? error.code : 'INTERNAL_SERVER_ERROR', |
| 110 | message: errorMessage, |
| 111 | docs: error instanceof ApiError ? error.docs : undefined |
| 112 | }); |
| 113 | }; |
| 114 | |
| 115 | // Main endpoint handler |
| 116 | const handleRun = async (c: any) => { |