Handling iframe upload errors
Hey thanks so much for this repo, I'm using it in a production environment and it's working great, except I need to handle upload errors and don't see any way to do so. I tried altering the response handler by extracting the status on complete. Google's docs suggest I should be able to call getStatus on the iframe or the event. I tried both.
(let [xhr (.-target event)](.-getStatus xhr)) ; xhr_29447.getStatus is not a function
(.getStatus event) ; event.getStatus is not a function
Any idea what I could be doing wrong ?
A lot will depend on the type of error you are talking about. The code I've done has little error checking (as you have discovered). Working from memory here, will need some time to look at this, which I just don't have right now.
There are really at least two levels of error you need to cater for. There are protocol type errors i.e. cannot connect to serrver, connection lost, server does not recognize request etc. These really need to be handled with iframe handlers. My code really only implements a handler for the completed case and does not check the status closely. However, the general form for these listners is the same. I think you just need to add one.
Then you need to handle the case where all the protocol stuff works, but the serrver detects an error in the data yuo have uploaded - for example, incorrect format or some other error generated when the server is processing the data you uploaded. In this case, I tend to use a json structure with a status value and in the case of an error status, an error message.
This approach gives more flexibility, but at the cost of some additional complexity as you need to now check for errors at two levels. If I had more time, I'd probably see how to amalgamate it so that we send back an error which is the same as a protcol error in form and we can then just have one error handling process.
Truth of the matter is I've found that cljs-ajax has been much easier and done everything I needed, so I've not used the direct iFrame approach much. My plan is to next look at using web sockets to do uploads which are large so that I can provide real-time progress feedback, which is nearly impossible to do well using the 'traditional' approaches. The problem with cljs-ajax is that it won't work if you must support older browsers. I don't need to as my audiences have been limited (corporate closed shop applications) were we can dictate the browser version.
I'll try to find time to look at this in the next few weeks.