This is my javascript code

var options = {
iframe: true,
type: 'post',
url: "api/Registration/Register",
data: { "data": jsonData },
dataType: 'json',
beforeSend: function () {
$('#result').html('Loading response...');
},
beforeSubmit: function (formData, formObject, formOptions) {


},
uploadProgress: function (event, position, total, percentComplete) {
},
success: function (responseText, statusText, xhr, $form) {

if (statusText == 'success') {

}
else { //code == 'FAIL'

}
}
})
},

error: function (response, status, err) {

},
};
$('#registration').ajaxSubmit(options);



and my controller looks like this


[HttpPost]
public Task<HttpResponseMessage> Register()
{

var task = Request.Content.ReadAsMultipartAsync(provider).
ContinueWith<HttpResponseMessage>(t =>
{

var response = new HttpResponseMessage
{
StatusCode = HttpStatusCode.OK,
Content = new StringContent(JsonConvert.SerializeObject(assistedRegResponse.Response))
};
return response;
return Request.CreateResponse(HttpStatusCode.OK);
}
catch (Exception ex)
{
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
}
});

return task;
}


but whenever there is an error or Exception it always goes to success callback. what i am missing here?