Ajax promise reject should return Error instead of message
This commit is contained in:
parent
2086d20192
commit
f2e887c23d
@ -45,7 +45,7 @@ export default class uAjax {
|
||||
* @param {Object|HTMLFormElement} [data] Optional request parameters: key/value pairs or form element
|
||||
* @param {Object} [options] Optional options
|
||||
* @param {string} [options.method='GET'] Optional query method, default 'GET'
|
||||
* @return {Promise<Object, string>}
|
||||
* @return {Promise<Object, Error>}
|
||||
*/
|
||||
static ajax(url, data, options) {
|
||||
const params = [];
|
||||
@ -78,10 +78,10 @@ export default class uAjax {
|
||||
message = `HTTP error ${xhr.status}`;
|
||||
}
|
||||
if (error && reject && typeof reject === 'function') {
|
||||
reject(message);
|
||||
reject(new Error(message));
|
||||
}
|
||||
};
|
||||
let body = null;
|
||||
let body;
|
||||
if (data instanceof HTMLFormElement) {
|
||||
if (method === 'POST') {
|
||||
body = new FormData(data);
|
||||
|
@ -109,8 +109,8 @@ describe('Ajax tests', () => {
|
||||
// then
|
||||
uAjax.get(url)
|
||||
.then(() => done.fail('resolve callback called'))
|
||||
.catch((message) => {
|
||||
expect(message).toBe(errorResponse.message);
|
||||
.catch((e) => {
|
||||
expect(e.message).toBe(errorResponse.message);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -122,8 +122,8 @@ describe('Ajax tests', () => {
|
||||
// then
|
||||
uAjax.get(url)
|
||||
.then(() => done.fail('resolve callback called'))
|
||||
.catch((message) => {
|
||||
expect(message).toBe('');
|
||||
.catch((e) => {
|
||||
expect(e.message).toBe('');
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -135,8 +135,8 @@ describe('Ajax tests', () => {
|
||||
// then
|
||||
uAjax.get(url)
|
||||
.then(() => done.fail('resolve callback called'))
|
||||
.catch((message) => {
|
||||
expect(message).toBe(`HTTP error ${status}`);
|
||||
.catch((e) => {
|
||||
expect(e.message).toBe(`HTTP error ${status}`);
|
||||
done();
|
||||
});
|
||||
});
|
||||
@ -148,8 +148,8 @@ describe('Ajax tests', () => {
|
||||
// then
|
||||
uAjax.get(url)
|
||||
.then(() => done.fail('resolve callback called'))
|
||||
.catch((message) => {
|
||||
expect(message).toContain('JSON');
|
||||
.catch((e) => {
|
||||
expect(e.message).toContain('JSON');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user