Reputation: 241
When I make CORS request and server returns 401 code in response I can't get any valuable response info (status = 0, responseText is empty).
On extjs side I use rest proxy with overridden method:
doRequest : function(request) {
var me = this,
requestConfig = request.getConfig();
requestConfig.cors = true;
requestConfig.useDefaultXhrHeader = false;
Ext.Ajax.cors = true;
Ext.Ajax.useDefaultXhrHeader = false;
me.callParent([request]);
},
In browser(Chrome) I can find that the response has 401 error code and some headers. But when I try to process the response in following method of proxy:
processResponse : function(success, operation, request, response) {
var me = this;
if (response.status == 401 || response.status == 403) {
me.handleSecurityError(response);
} else {
me.callParent([success, operation, request, response]);
}
},
I got only success = false and empty response.
Also on backend side I have a spring authentication filter: when I throw an authentication exception in the filter I get empty response, but when I return ResponseEntity with any code from controller I get valuable response.
What will I have to do to get at least an error code?
Upvotes: 0
Views: 388
Reputation: 36
How do you configure you cors?
most likely springSecurityFilterChain
is placed before your cors filter, so cors filter is not invoked.
@Component
@Order(Ordered.HIGHEST_PRECEDENCE)
public class SimpleCorsFilter implements Filter
try to place @Order(Ordered.HIGHEST_PRECEDENCE)
so the cors filter will be invoked before springSecurityFilterChain
Upvotes: 1