mikehostetler / amplify

AmplifyJS
http://amplifyjs.com
GNU General Public License v2.0
1.45k stars 143 forks source link

jsend decoder - throw an error when status is unknown #52

Closed brianmhunt closed 12 years ago

brianmhunt commented 12 years ago

This is a simple change, which would be as follows:

amplify.request.decoders = {
  jsend: function( data, status, ampXHR, success, error ) {
        var handled = false; // ADDED
        if ( data.status === "success" ) {
            success( data.data );
            handled = true; // ADDED
        } else if ( data.status === "fail" ) {
            error( data.data, "fail" );
            handled = true; // ADDED
        } else if ( data.status === "error" ) {
            delete data.status;
            error( data, "error" );
            handled = true; // ADDED
        }
        if (!handled) {
            throw "JSON response does not conform to jsend spec";
        } // ADDED
    }
}

This can help track down nasty oversights, especially with spelling errors e.g. "suceess".

scottgonzalez commented 12 years ago

You apparently duplicated yourself in #60 :-P

brianmhunt commented 12 years ago

lol. Thanks.