1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

Contacts: Save status code and header functions in response object.

This commit is contained in:
Thomas Tanghus 2013-05-03 05:56:55 +02:00
parent 514672ba3d
commit d435175b4e

View File

@ -7,7 +7,10 @@ OC.Contacts = OC.Contacts || {};
(function(window, $, OC) {
'use strict';
var JSONResponse = function(response) {
var JSONResponse = function(response, jqXHR) {
this.getAllResponseHeaders = jqXHR.getAllResponseHeaders;
this.getResponseHeader = jqXHR.getResponseHeader;
this.status = jqXHR.status;
if(!response || !response.status || response.status === 'error') {
this.error = true;
this.message = response.data.message || 'Unknown error.';
@ -418,6 +421,7 @@ OC.Contacts = OC.Contacts || {};
type: type,
url: url,
dataType: 'json',
ifModified: true,
contentType: contentType,
processData: processData,
data: params
@ -426,15 +430,15 @@ OC.Contacts = OC.Contacts || {};
var defer = $.Deferred();
var jqxhr = $.ajax(ajaxParams)
.done(function(response) {
defer.resolve(new JSONResponse(response));
.done(function(response, textStatus, jqXHR) {
defer.resolve(new JSONResponse(response, jqXHR));
})
.fail(function(jqxhr, textStatus, error) {
defer.reject(
new JSONResponse({
error:true,
data:{message:t('contacts', 'Request failed: {error}', {error:textStatus + ', ' + error})}
})
}, jqXHR)
);
});