PDA

View Full Version : [CLOSED] Issue returning error(s) from an Api Controller



ATLAS
May 22, 2014, 2:34 PM
I have a FormPanel that contains a FileUploadField and which invokes an Api Controller action using a DirectEvent in this way :-



Html.X().Button()
.ID("EXT_CERTIFYAWARD_BUTTON")
.Text(GlobalResources.CertifyAward)
.Icon(Icon.RosetteBlue)
.Margin(5)
.DirectEvents(de =>
{
de.Click.Url = @Url.RouteUrl("AlternateApi", new { httproute = "", controller = "AdministrationApi", action = "CertifyAward" });
de.Click.EventMask.ShowMask = true;
de.Click.FormID = "EXT_CERTIFYAWARD_FORMPANEL";
de.Click.IsUpload = true;
de.Click.Success = "onCertifyAwardSuccess(result);";
de.Click.Failure = "onCertifyAwardFailure(result);";
}),


If the Api Controller action returns Request.CreateResponse(HttpStatusCode.OK), all is well. The issue is when I have to return an error. The browser hangs for a long time (30 secs or so) and I get an error in the returned AXD of "Access Denied" which seems to be associated with "onUploadComplete".

To test error return methods I simply return an error response. I tried both throwing a HttpResponseException and also returning a CreateErrorResponse like this :-



[System.Web.Http.HttpPost]
public async Task<HttpResponseMessage> CertifyAward()
{

throw new HttpResponseException(Request.CreateErrorResponse(
HttpStatusCode.BadRequest,
"OMG, I like totally FAILED."));

// Verify that this is an HTML Form file upload request
if (!Request.Content.IsMimeMultipartContent("form-data"))
{
return Request.CreateErrorResponse(HttpStatusCode.Unsuppo rtedMediaType, "Unsupported Media Type.");
}
}


Both the above result in the "Access Denied" AXD error. To try and track down error further I used an override of onUploadComplete (only partially listed) :-



<script type="text/javascript">
Ext.data.Connection.override({
onUploadComplete: function(frame, options) {
var me = this, // bogus response object
response = {
responseText: '',
responseXML: null
}, doc, contentNode;
try {
doc = frame.contentWindow.document || frame.contentDocument || window.frames[frame.id].document;
.
.
.


The "Access Denied" seems to pertain to frame.contentWindow

Any clues?

Daniil
May 22, 2014, 6:35 PM
Hi @ATLAS,

We are not sure it is going to work with such kind of responses. Though, needs to investigate in details. It is appreciated if you can provide us with a full and simplified sample how to reproduce the problem.