createStubRequest doesn't wrap errors in HTTPError
chawes13 opened this issue · 0 comments
chawes13 commented
https://github.com/LaunchPadLab/lp-requests/blob/master/src/http-error.js
This makes accessing the error different when working with lp-form
. The appropriate information isn't passed to the errors
object passed in as the first argument to onSubmitFail
export const addTodo = createStubRequest('ADD_TODO', ({ title }) => {
if (title.toLowerCase().includes('nap')) throw new Error("There's no time for naps!")
return { title, description: "", completed: false, id: 6 }
})
<AddTodoForm
onSubmit={addTodo}
onSubmitFail={(errors, _, submitError) => {
// errors = {}, submitError = { errors: {}, meta: { error: 'No naps allowed' } }
const message =
errors.message || 'Could not add todo. Please try again'
}}
/>
Alternatively, we could make try to make this request library independent and enhance the error message identification here: https://github.com/LaunchPadLab/lp-form/blob/master/src/middleware/wrapSubmissionPromise.js#L16