How to use status Code in app.request?

Hi, I have a problem with the method app.request. If the response of the server is something as 401, 404 and so on, the StatusCode is not executed and the app executes the same the success. where is the mistake?
Thank you in advance

    app.request({ 
         url: url,
         method: 'POST',
         dataType: 'json',
         statusCode: {
		    401: function (xhr) {
		           app.preloader.hide();
		      	   app.dialog.alert('[400] Spiacenti, si è verificato un errore');
		    },
		    404: function (xhr) {
		           app.preloader.hide();
		      	   app.dialog.alert('[400] Spiacenti, si è verificato un errore');
		    },
		    500: function (xhr) {
		           app.preloader.hide();
		      	   app.dialog.alert('[400] Spiacenti, si è verificato un errore');
		    }
		},//status code
      	method: 'POST',
        data: {keys:k,identity:storedData.username, password:storedData.password},
        success: function (data) {           		
        			console.log('success');
        },//success
       
        error: function(){
        		console.log('error');
        }//error
	});//request

Issue is somewhere on your side, go to http://framework7.io/kitchen-sink/core/
and run in console:

app.request({ 
    url: 'somewhere',
    method: 'POST',
    dataType: 'json',
    statusCode: {
    401: function (xhr) {
      app.dialog.alert('[401] Spiacenti, si è verificato un errore');
    },
    404: function (xhr) {
      app.dialog.alert('[404] Spiacenti, si è verificato un errore');
    },
    500: function (xhr) {
      app.dialog.alert('[500] Spiacenti, si è verificato un errore');
    }
},//status code
    method: 'POST',
    data: {},
    success: function (data) {           		
          console.log('success');
    },//success
    
    error: function(){
        console.log('error');
    }//error
});//request

You will see it works as expected

1 Like

It’s true, it works on the console.