diff --git a/src/util/errors.js b/src/util/errors.js index 44f23633..a17ce45a 100644 --- a/src/util/errors.js +++ b/src/util/errors.js @@ -11,6 +11,9 @@ import { ERROR_CODE_TRANSACTION_LISTING_NOT_FOUND, + ERROR_CODE_TRANSACTION_INVALID_TRANSITION, + ERROR_CODE_TRANSACTION_ALREADY_REVIEWED_BY_CUSTOMER, + ERROR_CODE_TRANSACTION_ALREADY_REVIEWED_BY_PROVIDER, ERROR_CODE_PAYMENT_FAILED, ERROR_CODE_EMAIL_TAKEN, ERROR_CODE_EMAIL_NOT_FOUND, @@ -123,6 +126,25 @@ export const isTransactionInitiateAmountTooLowError = error => { }); }; +/** + * Check if the given API error (from `sdk.transactions.transition(id, transition, params)`) + * is due to invalid transition attempt. + */ +export const isTransactionsTransitionInvalidTransition = error => + error && + error.status === 409 && + hasErrorWithCode(error, ERROR_CODE_TRANSACTION_INVALID_TRANSITION); + +/** + * Check if the given API error (from `sdk.transactions.transition(id, transition, params)`) + * is due to already sent review. + */ +export const isTransactionsTransitionAlreadyReviewed = error => + error && + error.status === 409 && + (hasErrorWithCode(error, ERROR_CODE_TRANSACTION_ALREADY_REVIEWED_BY_CUSTOMER) || + hasErrorWithCode(error, ERROR_CODE_TRANSACTION_ALREADY_REVIEWED_BY_PROVIDER)); + /** * Check if the given API error (from `sdk.currentUser.changeEmail(params)`) * is due to giving wrong password. diff --git a/src/util/propTypes.js b/src/util/propTypes.js index 12e3cb4c..1eb451af 100644 --- a/src/util/propTypes.js +++ b/src/util/propTypes.js @@ -312,6 +312,11 @@ export const pagination = shape({ }); export const ERROR_CODE_TRANSACTION_LISTING_NOT_FOUND = 'transaction-listing-not-found'; +export const ERROR_CODE_TRANSACTION_INVALID_TRANSITION = 'transaction-invalid-transition'; +export const ERROR_CODE_TRANSACTION_ALREADY_REVIEWED_BY_CUSTOMER = + 'transaction-already-reviewed-by-customer'; +export const ERROR_CODE_TRANSACTION_ALREADY_REVIEWED_BY_PROVIDER = + 'transaction-already-reviewed-by-provider'; export const ERROR_CODE_PAYMENT_FAILED = 'transaction-payment-failed'; export const ERROR_CODE_EMAIL_TAKEN = 'email-taken'; export const ERROR_CODE_EMAIL_NOT_FOUND = 'email-not-found'; @@ -320,6 +325,9 @@ export const ERROR_CODE_TOO_MANY_VERIFICATION_REQUESTS = 'email-too-many-verific export const ERROR_CODE_UPLOAD_OVER_LIMIT = 'request-upload-over-limit'; const ERROR_CODES = [ ERROR_CODE_TRANSACTION_LISTING_NOT_FOUND, + ERROR_CODE_TRANSACTION_INVALID_TRANSITION, + ERROR_CODE_TRANSACTION_ALREADY_REVIEWED_BY_CUSTOMER, + ERROR_CODE_TRANSACTION_ALREADY_REVIEWED_BY_PROVIDER, ERROR_CODE_PAYMENT_FAILED, ERROR_CODE_EMAIL_TAKEN, ERROR_CODE_EMAIL_NOT_FOUND,