Map stripe idempotency errors to 400

This commit is contained in:
Ravi Khadiwala
2024-12-02 13:33:56 -06:00
committed by ravi-signal
parent a99ac14c6a
commit cc7bb8b549
2 changed files with 25 additions and 15 deletions

View File

@@ -343,9 +343,14 @@ public class SubscriptionController {
public record Error(SetSubscriptionLevelErrorResponse.Error.Type type, String message) {
public enum Type {
// The requested level was invalid
UNSUPPORTED_LEVEL,
// The requested currency was invalid
UNSUPPORTED_CURRENCY,
// The card could not be charged
PAYMENT_REQUIRES_ACTION,
// The request arguments were invalid representing a programmer error
INVALID_ARGUMENTS
}
}
}
@@ -391,6 +396,12 @@ public class SubscriptionController {
SetSubscriptionLevelErrorResponse.Error.Type.PAYMENT_REQUIRES_ACTION, null))))
.build());
}))
.exceptionally(ExceptionUtils.exceptionallyHandler(SubscriptionException.InvalidArguments.class, e -> {
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST)
.entity(new SetSubscriptionLevelErrorResponse(List.of(new SetSubscriptionLevelErrorResponse.Error(
SetSubscriptionLevelErrorResponse.Error.Type.INVALID_ARGUMENTS, e.getMessage()))))
.build());
}))
.thenApply(unused -> Response.ok(new SetSubscriptionLevelSuccessResponse(level)).build());
}