Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
const response = await fetch(`${API_BASE_URL}/documents/${roomName}`);
const json = await response.json();
if (json.length === 0) {
return false;
}
await dispatch(fetchDocsFromDbSuccess(json[0]));
return;
}
catch (err) {
dispatch(fetchDocsFromDbError(err));
const { reason, message, location, } = err;
if (reason === 'ValidationError') {
// Convert ValidationErrors into SubmissionErrors for Redux Form
return Promise.reject(
new SubmissionError({ [location]: message, })
);
}
}
}
// handle errors
var errors = {}
keys(body).forEach(key => {
let eKey = key
if(key === 'non_field_errors' || key === 'nonFieldErrors' || key === 'detail') {
eKey = '_error'
}
if(Array.isArray(body[key])) {
errors[eKey] = body[key][0]
} else {
errors[eKey] = body[key]
}
})
throw new SubmissionError(errors)
})
}
}).catch(error => {
throw new SubmissionError(error)
})
}
function* createProject(action: any): Generator<*, *, *> {
try {
const response = yield call(projectApi.createProject, action.data);
action.resolve(response);
yield put(pushHistory(routes.getProjectPath(action.data.name)));
} catch (e) {
console.error("createProject -> error", e);
action.reject(new SubmissionError({_error: e.message}));
}
}
.catch((error) => {
console.error('login failed', error)
const formErrors = mapSubmitErrorsToFormErrors(error, acceptedErrors)
throw new SubmissionError(formErrors)
}),
onClickResetPassword: ({ formEmail, onClickResetPassword }) => () =>
async handleSubmit(values) {
const { dispatch, identity } = this.props
const { password } = values
this.props.onSubmit(identity)
try {
await dispatch(identyListActions.login(identity, password))
} catch(err) {
throw new SubmissionError({ _error: err })
}
}
function* verifyChangePasswordIterator({ payload }) {
try {
yield call(post, '/user/me/changePassword/verify', payload);
yield put(verifyChangePassword.success());
yield call([Toast, Toast.green], { message: 'Password changed' });
yield put(resetStore());
} catch (e) {
yield put(verifyChangePassword.failure(new SubmissionError({ _error: e.error })));
yield call([Toast, Toast.red], { message: e.message });
}
}
.catch(err => reject(err instanceof errors.BadRequest
? new SubmissionError(Object.assign({}, err.errors, { _error: err.message || '' }))
: err
));
});
export default function normalizeFormError(error: {
statusCode: number,
body: string,
}) {
if (error.statusCode === 400 && error.body) {
throw new SubmissionError(error.body);
}
return Promise.reject(error);
}
function* verifyRestorePasswordIterator({ payload }) {
try {
yield call(post, '/user/resetPassword/verify', payload);
yield put(verifyRestorePassword.success());
yield put(notify('success', 'Password changed'));
yield put(push(namedRoutes.signIn));
} catch (e) {
yield put(verifyRestorePassword.failure(new SubmissionError({ _error: e.error })));
yield put(notify('error', e.error));
}
}