Effect CommunityEC
Effect Community9mo ago
1 reply
danielo515

Issue with Error Response Parsing in Endpoint Code

Does this look like a proper way of returning an error response from an endpoint? I'm getting parsing errors in the case I hit the error case:
export class ExecutionNotAllowed
  extends Schema.TaggedError<ExecutionNotAllowed>()('ExecutionNotAllowed', {
    message: Schema.String,
  }, HttpApiSchema.annotations({ status: 400 }))
{}

const ExecutorApiLive = HttpApiBuilder
  .group(
    apiSpec,
    'theGroup',
    handlers =>
      handlers
        .handle(
          'endpoint',
          Effect.fn('handlers.endpoint')(function*({ payload }) {
            return yield* whatever(payload)
              .pipe(
                Effect.map(() => ({ status: 'ok' as const })),
                Effect.catchTag('ExecutionRejected', () =>
                  ExecutionNotAllowed
                    .make({
                      message: 'Not allowed',
                    })),
              )
          }),
        ),
  )
Was this page helpful?