Error check for invalid transition: isTransactionsTransitionInvalidTransition

This commit is contained in:
Vesa Luusua 2017-11-28 19:07:58 +02:00
parent e75fe995f0
commit 345909611f
2 changed files with 30 additions and 0 deletions

View file

@ -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.

View file

@ -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,