-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #384 from Adyen/feature/AD-219-1
AD-219 Enhance Error Handling for Payment and Order Placement Steps
- Loading branch information
Showing
38 changed files
with
495 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...src/com/adyen/commerce/controllers/exceptionhandlers/AdyenControllerExceptionHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.adyen.commerce.controllers.exceptionhandlers; | ||
|
||
import com.adyen.commerce.exceptions.AdyenControllerException; | ||
import com.adyen.commerce.response.ErrorResponse; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.ControllerAdvice; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
|
||
@ControllerAdvice | ||
public class AdyenControllerExceptionHandler { | ||
|
||
@ExceptionHandler(value = AdyenControllerException.class) | ||
public ResponseEntity<ErrorResponse> handleAdyenControllerException(AdyenControllerException exception) { | ||
return ResponseEntity.badRequest().body(exception.getErrorResponse()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...napi/acceleratoraddon/web/src/com/adyen/commerce/exceptions/AdyenControllerException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.adyen.commerce.exceptions; | ||
|
||
import com.adyen.commerce.response.ErrorResponse; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AdyenControllerException extends RuntimeException { | ||
|
||
private final ErrorResponse errorResponse; | ||
|
||
public AdyenControllerException(String errorCode, List<String> invalidFields) { | ||
errorResponse = new ErrorResponse(errorCode, invalidFields); | ||
} | ||
|
||
public AdyenControllerException() { | ||
errorResponse = new ErrorResponse("checkout.error.default", new ArrayList<>()); | ||
} | ||
|
||
public AdyenControllerException(String errorCode) { | ||
errorResponse = new ErrorResponse(errorCode); | ||
} | ||
|
||
public ErrorResponse getErrorResponse() { | ||
return errorResponse; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...ncheckoutaddonapi/acceleratoraddon/web/src/com/adyen/commerce/response/ErrorResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.adyen.commerce.response; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ErrorResponse { | ||
private String errorCode; | ||
private List<String> invalidFields; | ||
|
||
public ErrorResponse(String errorCode, List<String> invalidFields) { | ||
this.errorCode = errorCode; | ||
this.invalidFields = invalidFields; | ||
} | ||
|
||
public ErrorResponse() { | ||
this.errorCode = "checkout.error.default"; | ||
this.invalidFields = new ArrayList<>(); | ||
} | ||
|
||
public ErrorResponse(String errorCode) { | ||
this.errorCode = errorCode; | ||
this.invalidFields = new ArrayList<>(); | ||
} | ||
|
||
public String getErrorCode() { | ||
return errorCode; | ||
} | ||
|
||
public List<String> getInvalidFields() { | ||
return invalidFields; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,8 @@ | |
margin-top: 30px; | ||
padding: 15px; | ||
border-radius: 12px; | ||
} | ||
|
||
.alert { | ||
scroll-margin-top: 10px; | ||
} |
22 changes: 22 additions & 0 deletions
22
...eb/webroot/_ui/responsive/common/js/adyen-checkout/src/components/common/ErrorHandler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {AxiosError} from "axios"; | ||
import {ErrorResponse} from "../../types/errorResponse"; | ||
import {isEmpty} from "../../util/stringUtil"; | ||
import {store} from "../../store/store"; | ||
import {createDefaultResponseData, createError} from "../../util/notificationUtil"; | ||
|
||
export class ErrorHandler { | ||
|
||
public static handleError(error?: AxiosError<ErrorResponse>) { | ||
let errorResponseData | ||
if (!error) { | ||
errorResponseData = createDefaultResponseData() | ||
} else { | ||
errorResponseData = error.response.data; | ||
|
||
if (!errorResponseData || isEmpty(errorResponseData.errorCode)) { | ||
errorResponseData = createDefaultResponseData() | ||
} | ||
} | ||
store.dispatch({type: "notifications/addNotification", payload: createError(errorResponseData)}) | ||
} | ||
} |
Oops, something went wrong.