Rovak / InlineAttachment

Easily paste and upload files/images in plain textareas
http://git.razko.nl/InlineAttachment
MIT License
619 stars 77 forks source link

Error handling #9

Closed micho closed 11 years ago

micho commented 11 years ago

I'm considering adding an error callback to react if the file wasn't uploaded correctly.

I believe this should be overridable. Do you have any ideas about this, or would you like me to send a PR with it?

Rovak commented 11 years ago

That would be a really good addition, what would be the desired default behavior when an upload fails? Just remove the inserted "![]()" which would be confusing because it does not give the user any good feedback. Or let the programmer return an error message in the resulting server response inside a JSON "error" key which then would be inserted in place of the image link, and remove after a timeout?

I would like to have the option to return a 500 code which results in a default error message (also configurable?) or an error value which can be returned by the server.

micho commented 11 years ago

In my current implementation, it displays an alert("Upload failed, check your connectivity") and removes the text. This message is customizable via settings.errorText. We could add different error messages for server error or AJAX timeout error.

A programmer could supply their own callback, but this makes me wonder about the more general idea of handling custom callbacks.

Rovak commented 11 years ago

The custom callback could return false to prevent the default behavior from executing, this would be the most simplest way to override the behavior while giving the choice to run default behavior when false is not returned.

Rovak commented 11 years ago

@micho Could you PR your current implementation?

micho commented 11 years ago

Uploaded code here:

https://github.com/Rovak/InlineAttachment/pull/12