Update parse SDK to 2.0.0 (#4925)
* WIP: Integrate JS SDK v2 - Removes backbone style callbacks - Use Promise instead of Parse.Promise * Fixes ParseObject and ParseRelation * Updates Parse.Query with promises * Alls tests should pass * Ensure a fresh user is used for each test * Use REST implementation to avoid side effects for username/email duplicates * Uses js sdk v2
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import request from 'request';
|
||||
import Parse from 'parse/node';
|
||||
import HTTPResponse from './HTTPResponse';
|
||||
import querystring from 'querystring';
|
||||
import log from '../logger';
|
||||
@@ -35,7 +34,6 @@ var encodeBody = function({body, headers = {}}) {
|
||||
}
|
||||
|
||||
module.exports = function(options) {
|
||||
var promise = new Parse.Promise();
|
||||
var callbacks = {
|
||||
success: options.success,
|
||||
error: options.error
|
||||
@@ -54,30 +52,30 @@ module.exports = function(options) {
|
||||
}
|
||||
// force the response as a buffer
|
||||
options.encoding = null;
|
||||
return new Promise((resolve, reject) => {
|
||||
request(options, (error, response, body) => {
|
||||
if (error) {
|
||||
if (callbacks.error) {
|
||||
callbacks.error(error);
|
||||
}
|
||||
return reject(error);
|
||||
}
|
||||
const httpResponse = new HTTPResponse(response, body);
|
||||
|
||||
request(options, (error, response, body) => {
|
||||
if (error) {
|
||||
if (callbacks.error) {
|
||||
callbacks.error(error);
|
||||
// Consider <200 && >= 400 as errors
|
||||
if (httpResponse.status < 200 || httpResponse.status >= 400) {
|
||||
if (callbacks.error) {
|
||||
callbacks.error(httpResponse);
|
||||
}
|
||||
return reject(httpResponse);
|
||||
} else {
|
||||
if (callbacks.success) {
|
||||
callbacks.success(httpResponse);
|
||||
}
|
||||
return resolve(httpResponse);
|
||||
}
|
||||
return promise.reject(error);
|
||||
}
|
||||
const httpResponse = new HTTPResponse(response, body);
|
||||
|
||||
// Consider <200 && >= 400 as errors
|
||||
if (httpResponse.status < 200 || httpResponse.status >= 400) {
|
||||
if (callbacks.error) {
|
||||
callbacks.error(httpResponse);
|
||||
}
|
||||
return promise.reject(httpResponse);
|
||||
} else {
|
||||
if (callbacks.success) {
|
||||
callbacks.success(httpResponse);
|
||||
}
|
||||
return promise.resolve(httpResponse);
|
||||
}
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
};
|
||||
|
||||
module.exports.encodeBody = encodeBody;
|
||||
|
||||
Reference in New Issue
Block a user