react-widget
react-widget copied to clipboard
There is no onError props or a way to check if the upload didn't work
Brief description of the feature and motivation behind it
I'm using a custom button that opens up the Uploadcare widget. Once the file is selected, the widget is closed and a loading state is displayed (and form submission is disabled) until the onChange function fires and the selected file name is displayed in the button. Now it has happened two days in a row that the file upload does not succeed and the onChange function does not fire, leaving me with a hanging loading state.
Can the onChange function fire with error props? Or is it possible to add onError props to the widget so that I can react accordingly and display that an error occured?
Some way to check if the upload does not succeed. This could be a new props or addition to the onChange.
I think error handling is important. Some users don't want to use the widget button that comes with the package.
Hi @jonnigs , you can handle upload errors this way:
<Widget
onDialogOpen={(dialog) => {
dialog.fileColl.onAdd.add((file) => {
file.fail((errorType, fileInfo, error) => {
console.error(errorType, error);
});
});
}}
/>
This will work with both single and multiple uploads. More info about the file.fail
method can be found here. Dialog and File Collection methods are covered in this docs article.
Thank you for this! I completely missed this in the docs.
I think the issue/feature request still holds, onError prop in the widget would be nice and easier to work with.