fix: default error message
This commit is contained in:
parent
ac489266c6
commit
1d2ca19c2d
1 changed files with 11 additions and 6 deletions
|
|
@ -15,6 +15,9 @@ import CouponCodesModal from './CouponCodesModal'
|
||||||
|
|
||||||
const useStyles = makeStyles(styles)
|
const useStyles = makeStyles(styles)
|
||||||
|
|
||||||
|
const DUPLICATE_ERROR_MSG = 'There is already a coupon with that code!'
|
||||||
|
const DEFAULT_ERROR_MSG = 'Failed to save'
|
||||||
|
|
||||||
const GET_COUPONS = gql`
|
const GET_COUPONS = gql`
|
||||||
query coupons {
|
query coupons {
|
||||||
coupons {
|
coupons {
|
||||||
|
|
@ -69,16 +72,18 @@ const Coupons = () => {
|
||||||
if (!res.errors) {
|
if (!res.errors) {
|
||||||
return setShowModal(false)
|
return setShowModal(false)
|
||||||
} else {
|
} else {
|
||||||
const duplicateCouponError = res.errors.some(e => {
|
const duplicateCouponError = R.any(it =>
|
||||||
return e.message.includes('duplicate')
|
R.includes('duplicate', it?.message)
|
||||||
})
|
)(res.errors)
|
||||||
|
|
||||||
if (duplicateCouponError)
|
const msg = duplicateCouponError
|
||||||
setErrorMsg('There is already a coupon with that code!')
|
? DUPLICATE_ERROR_MSG
|
||||||
|
: DEFAULT_ERROR_MSG
|
||||||
|
setErrorMsg(msg)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
setErrorMsg('Failed to save')
|
setErrorMsg(DEFAULT_ERROR_MSG)
|
||||||
console.log(err)
|
console.log(err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue