Repository URL to install this package:
|
Version:
0.0.15 ▾
|
import { getTyped } from 'composition';
import { isErrorLikeResponse } from '@skava/is-error-like-response';
import { toastMessage, responseMessage } from '@skava/packages/core/notifications';
import { errorKeyWords } from '../fixture';
/**
* @todo @@graphql @@haircut
*/
function toStatus(response) {
return (getTyped(response).string('properties.state.status') ||
getTyped(response).string('responseMessage'));
}
/**
* @note we have no responseCode!!!!!!!!!!!!!
*/
function isErrorLikeResponseForUser(response) {
const status = toStatus(response);
// Additional check included for the status: "Old Password And New Password Can't Be Same"
const findErrorResponse = (key) => status.includes(key);
return errorKeyWords.some(findErrorResponse) || isErrorLikeResponse(response);
}
// @todo @graphql @@haircut
const fromResponseToToastMessage = (response) => {
const status = toStatus(response);
return isErrorLikeResponseForUser(response) ? status : toastMessage.updatePasswordSuccess;
};
// @todo @@graphql @@haircut
const fromErrorResponseToToastMessage = (response) => {
const status = toStatus(response);
switch (status) {
case responseMessage.accountValidation:
return toastMessage.unregisteredAccount;
case responseMessage.sameOldAndNewPassword:
return toastMessage.sameOldAndNewPassword;
case responseMessage.securityQuestionValidationFailure:
return toastMessage.securityQuestionValidation;
default:
return toastMessage.updatePasswordFailure;
}
};
export { toStatus, isErrorLikeResponseForUser, fromResponseToToastMessage, fromErrorResponseToToastMessage, };
//# sourceMappingURL=deps.js.map