Created
November 28, 2018 21:39
-
-
Save lucassimon/afb6541b4cfca8deef94cdb9b629e56f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onSubmit={ async (values, actions) => { | |
let attemps = 1 | |
while ( attemps <= 2) { | |
try { | |
await SupplierService.create(values, token) | |
actions.setSubmitting(false); | |
// TODO: Fetch the paginated data | |
handleOpenSnackBar('Registro inserido com sucesso', 'success') | |
close(); | |
console.log('Foi') | |
break | |
} catch (error) { | |
// cosnt response = await AuthServiceRefresh() | |
console.log(error) | |
console.log(error.response) | |
let subStatus = null | |
if (error.response && error.response.data) { | |
subStatus = error.response.data.sub_status | |
} | |
if (subStatus === 42) { | |
handleTokenExpired() | |
handleRefreshToken() | |
} else { | |
actions.setSubmitting(false); | |
let message = 'Contact the administrator.' | |
let extras = {} | |
if (error.response) { | |
message = error.response.data.message || error.message | |
extras = error.response.data.errors || {} | |
if (error.response.data.resource === 'Iugu') { | |
const keys = Object.keys(extras.errors) | |
extras = keys.map(v => (`${v}: ${extras.errors[v]}`)); | |
} | |
} | |
console.log(extras) | |
actions.setErrors({ apiErrors: message, extras }); | |
handleOpenSnackBar(message, 'danger') | |
break | |
} | |
} | |
console.log('Delay', 1000 * attemps) | |
await delay(1000 * attemps); | |
attemps = attemps + 1 | |
} | |
actions.setSubmitting(false); | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment