Skip to content

Commit 64e40b3

Browse files
committed
Improve error handling for uploads and defects
1 parent 5710536 commit 64e40b3

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

apps/api/src/routes/files.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ const uploadFile = Effect.gen(function* () {
100100
return yield* Effect.fail(new ValidationError({ message: 'path query parameter is required' }))
101101
}
102102

103-
// Read body as array buffer — catch @effect/platform RequestError
103+
// Read body as array buffer — catch all errors from body reading
104104
const arrayBuffer = yield* request.arrayBuffer.pipe(
105-
Effect.catchTag('RequestError', (err) =>
105+
Effect.catchAllCause((cause) =>
106106
Effect.fail(
107107
new InternalError({
108-
message: `Failed to read upload body: ${err.message}`,
108+
message: `Failed to read upload body: ${Cause.pretty(cause)}`,
109109
}),
110110
),
111111
),

apps/api/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { HttpMiddleware, HttpRouter, HttpServer, HttpServerRequest, HttpServerResponse } from '@effect/platform'
22
import { Effect } from 'effect'
33
import { auth } from './auth.js'
4-
import { formatApiError } from './errors.js'
4+
import { formatApiError, InternalError } from './errors.js'
55
import { withRequestId } from './middleware.js'
66
import { withConnectionDrain } from './middleware/connection-drain.js'
77
import { withRateLimit } from './middleware/rate-limit.js'
@@ -51,7 +51,7 @@ const withDefectHandler = HttpMiddleware.make((app) =>
5151
Effect.gen(function* () {
5252
const message = defect instanceof Error ? defect.message : String(defect)
5353
yield* Effect.logError(`Unhandled defect: ${message}`)
54-
return formatApiError(new Error('internal defect'))
54+
return formatApiError(new InternalError({ message }))
5555
}),
5656
),
5757
),

0 commit comments

Comments
 (0)