Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(http): fixed regression bug when handling synchronous errors inside the adapter; #5564

Merged
merged 25 commits into from Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3f2f496
chore(ci): Add release-it script;
DigitalBrainJS Dec 10, 2022
1bfc41b
Merge branch 'chore/release-it' into v1.x
DigitalBrainJS Dec 10, 2022
acaf0f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
8a5de86
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 15, 2022
cff9271
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 17, 2022
67afe20
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 19, 2022
dc7b66d
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 22, 2022
716eb59
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 23, 2022
10216bf
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Dec 29, 2022
3b199f4
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 7, 2023
f3d444f
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 19, 2023
077c381
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 26, 2023
f598657
Merge branch 'v1.x' of https://github.com/axios/axios into v1.x
DigitalBrainJS Jan 31, 2023
ffeb364
fix(serializer): fixed serialization of array-like objects;
DigitalBrainJS Feb 1, 2023
0908c4b
fix(http): treat `http://localhost` as base URL for relative paths to…
DigitalBrainJS Feb 3, 2023
5e74831
Merge branch 'v1.x' into fix/codebase
DigitalBrainJS Feb 3, 2023
35af573
Merge branch 'v1.x' of https://github.com/axios/axios into fix/codebase
DigitalBrainJS Feb 6, 2023
9cdacb8
fix(formdata): fixed setting NaN as Content-Length for form payload i…
DigitalBrainJS Feb 6, 2023
a8f1cd8
Merge remote-tracking branch 'origin/fix/codebase' into fix/codebase
DigitalBrainJS Feb 6, 2023
cc858aa
Merge branch 'v1.x' into fix/codebase
DigitalBrainJS Feb 11, 2023
f2e315d
Merge branch 'v1.x' of https://github.com/axios/axios into fix/codebase
DigitalBrainJS Feb 13, 2023
1c7270a
fix(formdata): added a check to ensure the `FormData` class is availa…
DigitalBrainJS Feb 13, 2023
a14e4a2
Merge remote-tracking branch 'origin/fix/codebase' into fix/codebase
DigitalBrainJS Feb 13, 2023
4e38a16
fix(http): fixed regression bug when handling synchronous errors insi…
DigitalBrainJS Feb 22, 2023
10b421a
Merge branch 'v1.x' into fix/codebase
DigitalBrainJS Feb 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 33 additions & 25 deletions lib/adapters/http.js
Expand Up @@ -116,26 +116,47 @@ function setProxy(options, configProxy, location) {

const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';

// temporary hotfix

const wrapAsync = (asyncExecutor) => {
return new Promise((resolve, reject) => {
let onDone;
let isDone;

const done = (value, isRejected) => {
if (isDone) return;
isDone = true;
onDone && onDone(value, isRejected);
}

const _resolve = (value) => {
done(value);
resolve(value);
};

const _reject = (reason) => {
done(reason, true);
reject(reason);
}

asyncExecutor(_resolve, _reject, (onDoneHandler) => (onDone = onDoneHandler)).catch(_reject);
})
};

/*eslint consistent-return:0*/
export default isHttpAdapterSupported && function httpAdapter(config) {
/*eslint no-async-promise-executor:0*/
return new Promise(async function dispatchHttpRequest(resolvePromise, rejectPromise) {
let data = config.data;
const responseType = config.responseType;
const responseEncoding = config.responseEncoding;
return wrapAsync(async function dispatchHttpRequest(resolve, reject, onDone) {
let {data} = config;
const {responseType, responseEncoding} = config;
const method = config.method.toUpperCase();
let isFinished;
let isDone;
let rejected = false;
let req;

// temporary internal emitter until the AxiosRequest class will be implemented
const emitter = new EventEmitter();

function onFinished() {
if (isFinished) return;
isFinished = true;

const onFinished = () => {
if (config.cancelToken) {
config.cancelToken.unsubscribe(abort);
}
Expand All @@ -147,26 +168,13 @@ export default isHttpAdapterSupported && function httpAdapter(config) {
emitter.removeAllListeners();
}

function done(value, isRejected) {
if (isDone) return;

onDone((value, isRejected) => {
isDone = true;

if (isRejected) {
rejected = true;
onFinished();
}

isRejected ? rejectPromise(value) : resolvePromise(value);
}

const resolve = function resolve(value) {
done(value);
};

const reject = function reject(value) {
done(value, true);
};
});

function abort(reason) {
emitter.emit('abort', !reason || reason.type ? new CanceledError(null, config, req) : reason);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -203,4 +203,4 @@
"@commitlint/config-conventional"
]
}
}
}
4 changes: 4 additions & 0 deletions test/unit/adapters/http.js
Expand Up @@ -2099,4 +2099,8 @@ describe('supports http with nodejs', function () {
}
});
})

it('should properly handle synchronous errors inside the adapter', function () {
return assert.rejects(() => axios.get('http://192.168.0.285'), /Invalid URL/);
});
});