mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-29 21:21:19 +10:00
Rename error parameter on funtions inside util/errors
This commit is contained in:
parent
9ad17224df
commit
296203ee82
1 changed files with 21 additions and 23 deletions
|
|
@ -29,15 +29,13 @@ const hasErrorWithCode = (apiError, code) => {
|
|||
* Check if the given API error (from `sdk.currentuser.create()`) is
|
||||
* due to the email address already being in use.
|
||||
*/
|
||||
export const isSignupEmailTakenError = apiError =>
|
||||
hasErrorWithCode(apiError, ERROR_CODE_EMAIL_TAKEN);
|
||||
export const isSignupEmailTakenError = error => hasErrorWithCode(error, ERROR_CODE_EMAIL_TAKEN);
|
||||
|
||||
/**
|
||||
* Check if the given API error (from `sdk.currentuser.changeEmail()`) is
|
||||
* due to the email address already being in use.
|
||||
*/
|
||||
export const isChangeEmailTakenError = apiError =>
|
||||
hasErrorWithCode(apiError, ERROR_CODE_EMAIL_TAKEN);
|
||||
export const isChangeEmailTakenError = error => hasErrorWithCode(error, ERROR_CODE_EMAIL_TAKEN);
|
||||
|
||||
/**
|
||||
* Check if the given API error (from
|
||||
|
|
@ -48,45 +46,44 @@ export const isChangeEmailTakenError = apiError =>
|
|||
* allowed, and the user has to wait for them to expire to be able to
|
||||
* request sending new verification emails.
|
||||
*/
|
||||
export const isTooManyEmailVerificationRequestsError = apiError =>
|
||||
hasErrorWithCode(apiError, ERROR_CODE_TOO_MANY_VERIFICATION_REQUESTS);
|
||||
export const isTooManyEmailVerificationRequestsError = error =>
|
||||
hasErrorWithCode(error, ERROR_CODE_TOO_MANY_VERIFICATION_REQUESTS);
|
||||
|
||||
/**
|
||||
* Check if the given API error (from
|
||||
* `sdk.images.uploadListingImage()`) is due to the image being over
|
||||
* the size limit.
|
||||
*/
|
||||
export const isUploadListingImageOverLimitError = apiError =>
|
||||
hasErrorWithCode(apiError, ERROR_CODE_UPLOAD_OVER_LIMIT);
|
||||
export const isUploadListingImageOverLimitError = error =>
|
||||
hasErrorWithCode(error, ERROR_CODE_UPLOAD_OVER_LIMIT);
|
||||
|
||||
/**
|
||||
* Check if the given API error (from
|
||||
* `sdk.images.uploadProfileImage()`) is due to the image being over
|
||||
* the size limit.
|
||||
*/
|
||||
export const isUploadProfileImageOverLimitError = apiError =>
|
||||
hasErrorWithCode(apiError, ERROR_CODE_UPLOAD_OVER_LIMIT);
|
||||
export const isUploadProfileImageOverLimitError = error =>
|
||||
hasErrorWithCode(error, ERROR_CODE_UPLOAD_OVER_LIMIT);
|
||||
|
||||
/**
|
||||
* Check if the given API error (from `sdk.passwordReset.request()`)
|
||||
* is due to no user having the given email address.
|
||||
*/
|
||||
export const isPasswordRecoveryEmailNotFoundError = apiError => apiError && apiError.status === 404;
|
||||
export const isPasswordRecoveryEmailNotFoundError = error => error && error.status === 404;
|
||||
|
||||
/**
|
||||
* Check if the given API error (from `sdk.passwordReset.request()`)
|
||||
* is due to the email not being verified, preventing the reset.
|
||||
*/
|
||||
export const isPasswordRecoveryEmailNotVerifiedError = apiError =>
|
||||
apiError && apiError.status === 409;
|
||||
export const isPasswordRecoveryEmailNotVerifiedError = error => error && error.status === 409;
|
||||
|
||||
/**
|
||||
* Check if the given API error (from `sdk.transaction.initiate()` or
|
||||
* `sdk.transaction.initiateSpeculative()`) is due to the listing
|
||||
* being closed or deleted.
|
||||
*/
|
||||
export const isTransactionInitiateListingNotFoundError = apiError => {
|
||||
return responseErrors(apiError).some(error => {
|
||||
export const isTransactionInitiateListingNotFoundError = error => {
|
||||
return responseErrors(error).some(apiError => {
|
||||
let notfound = false;
|
||||
|
||||
try {
|
||||
|
|
@ -94,12 +91,12 @@ export const isTransactionInitiateListingNotFoundError = apiError => {
|
|||
// the deleted information from the error and should be changed
|
||||
// to a proper error code when the API supports a specific code
|
||||
// for this.
|
||||
notfound = error.details.data.rep[0][1].reason === 'listing-not-found';
|
||||
notfound = apiError.details.data.rep[0][1].reason === 'listing-not-found';
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
return error.code === ERROR_CODE_TRANSITION_PARAMETER_VALIDATION_FAILED && notfound;
|
||||
return apiError.code === ERROR_CODE_TRANSITION_PARAMETER_VALIDATION_FAILED && notfound;
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -107,15 +104,16 @@ export const isTransactionInitiateListingNotFoundError = apiError => {
|
|||
* Check if the given API error (from `sdk.transaction.initiate()`) is
|
||||
* due to the transaction total amount being too low for Stripe.
|
||||
*/
|
||||
export const isTransactionInitiateAmountTooLowError = apiError => {
|
||||
return responseErrors(apiError).some(error => {
|
||||
const isPaymentFailedError = error.status === 402 && error.code === ERROR_CODE_PAYMENT_FAILED;
|
||||
export const isTransactionInitiateAmountTooLowError = error => {
|
||||
return responseErrors(error).some(apiError => {
|
||||
const isPaymentFailedError =
|
||||
apiError.status === 402 && apiError.code === ERROR_CODE_PAYMENT_FAILED;
|
||||
let isAmountTooLow = false;
|
||||
|
||||
try {
|
||||
// TODO: This is a temporary solution until a proper error code
|
||||
// for this specific error is received in the response.
|
||||
const msg = error.details.msg;
|
||||
const msg = apiError.details.msg;
|
||||
isAmountTooLow = msg.startsWith('Amount must be at least');
|
||||
} catch (e) {
|
||||
// Ignore
|
||||
|
|
@ -129,10 +127,10 @@ export const isTransactionInitiateAmountTooLowError = apiError => {
|
|||
* Check if the given API error (from `sdk.currentUser.changeEmail(params)`)
|
||||
* is due to giving wrong password.
|
||||
*/
|
||||
export const isChangeEmailWrongPassword = apiError => apiError && apiError.status === 403;
|
||||
export const isChangeEmailWrongPassword = error => error && error.status === 403;
|
||||
|
||||
/**
|
||||
* Check if the given API error (from `sdk.currentUser.changePassword(params)`)
|
||||
* is due to giving wrong password.
|
||||
*/
|
||||
export const isChangePasswordWrongPassword = apiError => apiError && apiError.status === 403;
|
||||
export const isChangePasswordWrongPassword = error => error && error.status === 403;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue