restful table and Stash problem...

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2014

Hey...

I am using AUI Restful Table in a Stash plugin. When the user submits invalid data I am returning a 400 status code as I believe is correct. I am binding to the event: AJS.RestfulTable.Events.VALIDATION_ERROR, and although my handler is being called, nothing seems to stop a big nasty dialog displaying the summary: 'Something went wrong while trying to serve your request. Try reloading the page.'.

This is coming from getDominantAJAXError in error. js - is there a way of just telling it that I will handle any non-OK status codes myself?

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Adam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 13, 2014

Attempt two, still not actually tested.

(function() {
var oldSync = Backbone.sync;
Backbone.sync = function(method, model, options) {
    if (model instanceof AJS.RestfulTable.EntryModel) {
        options = AJS.$.extend({
            statusCode : {
                400 : false
            }
        }, options);
    }
    return oldSync.apply(this, method, model, options);
};
})();

I have to special-case the EntryModel in the global sync method. This is ugly but should work (fingers crossed).

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 28, 2014

Thanks Adam - I abandoned restful table in the end, but this may come in useful somewhere else.

0 votes
Bernhard Gruenewaldt April 15, 2014

I am having similar problems with restfultable and validation for a jira plugin,

maybe you can help me here a little thx: https://answers.atlassian.com/questions/283773/aui-restfultable-validation-errors-not-displayed

0 votes
Adam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 12, 2014

Hi Jamie,

Restful Table and Stash don't play well together, currently. You should note that RestfulTable is experimental, so it may change unexpectedly.

We might offer a better alternative in the future, but for now if you want to use RestfulTable in Stash, you'll have to override the default model and use your own sync method. Here's one way you can do it:

var StashEntryModel = AJS.RestfulTable.EntryModel.extend({
    sync : function(method, model, opts) {
        return Backbone.sync(method, model, AJS.$.extend({
             statusCode : {
                 400 : false // ignore HTTP 400s.
             }
        }, opts));
    }
});
// Use our model instead of the default.
new AJS.RestfulTable({
    ...
    model : StashEntryModel
});

I haven't tested it, but that snippet should create a new kind of model that tells our ajax transport to ignore HTTP 400s during sync.

If you want to just ignore _all_ errors (including being logged out, or server going down, or other catastrophic errors), you can use `* : false` in place of `400 : false`. But generally that error handling is pretty useful.

Let me know if you find issues with it.

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2014

overriding "save" works though... but I still can't avoid the big server error message :-(

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2014

Hi Adam - thanks for your answer. It seems utterly plausible, but I'm falling at the very first hurdle. I can't even get my sync to run... the default EntryModel.sync is still being called. My code:

model: AJS.RestfulTable.EntryModel.extend({
                sync : function(method, model, opts) {
                    console.log("sync");
                    return Backbone.sync(method, model, AJS.$.extend({
                        statusCode : {
                            400 : false // ignore HTTP 400s.
                        }
                    }, opts));
                }
            }),

JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 12, 2014

Big bounty in it for you if you have any other ideas!

Adam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 13, 2014

Right, EntryModel's save method assumes you don't subclass it and references itself harcoded :/

Patrick van der Rijst
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 13, 2015

On the destroy function all the arguments are undefined so you can't see if there are validation errors.

TAGS
AUG Leaders

Atlassian Community Events