commercetools / commercetools-sunrise-java

The next generation shop framework by commercetools
https://demo.commercetools.com
Apache License 2.0
46 stars 35 forks source link

Extract exception handling to app controller level #645

Open lauraluiz opened 7 years ago

lauraluiz commented 7 years ago

Currently they are being handled all in the handleClientErrorFailedAction, but it would be better to be extracted and handled in the app.

Current:

// SunriseLogInController.java
    @Override
    public CompletionStage<Result> handleClientErrorFailedAction(final Void input, final Form<? extends LogInFormData> form, final ClientErrorException clientErrorException) {
        if (isCustomerInvalidCredentialsError(clientErrorException)) {
            saveFormError(form, "Invalid credentials"); // TODO i18n
            return showFormPageWithErrors(input, form);
        } else {
            return WithContentFormFlow.super.handleClientErrorFailedAction(input, form, clientErrorException);
        }
    }

To be:

// SunriseLogInController.java
    @Override
    public CompletionStage<Result> handleClientErrorFailedAction(final Void input, final Form<? extends LogInFormData> form, final ClientErrorException clientErrorException) {
        if (throwable instanceof ErrorResponseException 
 && isCustomerInvalidCredentialsError(clientErrorException)) {
            return handleCustomerInvalidCredentialsException(form, (ErrorResponseException) throwable);
        } else {
            return WithContentFormFlow.super.handleClientErrorFailedAction(input, form, clientErrorException);
        }
    }

protected abstract CompletionStage<Result> handleCustomerInvalidCredentialsException(final Form<? extends LogInFormData> form, final ErrorResponseException errorResponseException);