| 168 | // upgrade/websocket failures, so handle both shapes. |
| 169 | on: { |
| 170 | error(err, _req, res) { |
| 171 | console.error( |
| 172 | `tracedecay dev /api proxy error -> ${apiTarget}: ${err.message}`, |
| 173 | ); |
| 174 | if (res && typeof res.writeHead === "function") { |
| 175 | if (!res.headersSent) { |
| 176 | res.writeHead(502, { "Content-Type": "application/json" }); |
| 177 | res.end( |
| 178 | JSON.stringify({ |
| 179 | error: `dev proxy failed to reach ${apiTarget}`, |
| 180 | detail: err.message, |
| 181 | }), |
| 182 | ); |
| 183 | } |
| 184 | } else if (res && typeof res.destroy === "function") { |
| 185 | res.destroy(err); |
| 186 | } |
| 187 | }, |
| 188 | }, |
| 189 | }, |
| 190 | }, |