Unclear about handling of returned system messages with elgg/ajax AMD module methods

By iionly

I've rewritten large parts of Tidypics including changing the JS code to use elgg/ajax where appropriate.

I had some problems understanding how ajax.action works in general with regards to system message / error messages / returned output handling. Basically I had to change the code by trial and error. The docs might be alright if you already have a basic understanding of the underlying concepts but it didn't help me at all to be honest...

With the JS code re-creating all thumbnails I had to give up with trying to handle error messages as I just don't get what I would need to change due to the switch from elgg.action to ajax.action.

The code has been based on https://github.com/Elgg/Elgg/blob/3.x/views/default/elgg/upgrades.js where options.success handles error messages (json.system_messages.error) and outputs any new messages.

My new code is at https://github.com/iionly/tidypics/blob/master/views/default/js/tidypics/resize_thumbnails.js. Trying to check json.system_messages.error for messages within the done function fails now. As I understand the if (jqXHR.AjaxData.status == -1) {} part is executed if elgg_error_response() occurs (and I can fetch the error message from the json object). But register_error() error messages wouldn't trigger jqXHR.AjaxData.status == -1, right? How can I check for any such errors that might have occured then? How's the whole error handling flow influenced by "elgg_fetch_messages: 0" in data? I would have to set elgg_fetch_messages to false to be able to handle error message output on my own, right? But do I not get the error messages anymore at all then or how can I get system messages / error messages content now?