Effect CommunityEC
Effect Community9mo ago
25 replies
Dave Meehan

Simplifying Error Handling with Grouped Mappings in Effect Typescript

Is there a way to avoid doing this sort of thing all over the place - or at least be more succinct where the mapped result is the same for different error types?

      Effect.catchTags({
        SdkError: error => new DeviceRepositoryServerError({ message: error.message }),
        InternalServerError: error => new DeviceRepositoryServerError({ message: error.message }),
        RequestLimitExceeded: error => new DeviceRepositoryClientError({ message: error.message }),
        InvalidEndpointException: error => new DeviceRepositoryServerError({ message: error.message }),
        ProvisionedThroughputExceededException: error => new DeviceRepositoryClientError({ message: error.message }),
        ResourceNotFoundException: error => new DeviceRepositoryClientError({ message: error.message }),
        ItemCollectionSizeLimitExceededException: error => new DeviceRepositoryClientError({ message: error.message }),
        TransactionConflictException: error => new DeviceRepositoryClientError({ message: error.message }),
        ConditionalCheckFailedException: () => new DeviceRepositoryDuplicateError({ message: 'DeviceEUI already exists' }),
      }),


In most cases errors fall into either client or server problems, some are retryable, and few exceptions depending on context (ParseError on input intended to be sent to the client command, and output from the command that isn't in the expected format).
Was this page helpful?