Skip to content

Commit

Permalink
fix transports, catch errors (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxgithubprofile authored Aug 23, 2024
1 parent 2055a10 commit 7239695
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
4 changes: 3 additions & 1 deletion proxy16/node/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function rpc(request, callback, obj) {
var reqf = self.transports?.axios || axios

config.method = 'post'

//config.signal = signal


try{
Expand All @@ -291,6 +291,8 @@ function rpc(request, callback, obj) {
return
}



reqf({

url,
Expand Down
37 changes: 30 additions & 7 deletions proxy16/transports.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,31 @@ class WrappedAxios {
return axios(preparedArgs)
.then(WrappedAxios.handleSuccess)
.catch(async (error) => {

const isAgentAttached = WrappedAxios.isAgentAttached(preparedArgs);
const isAgentError = this.transports.checkForAgentError(error);

if (isAgentAttached && isAgentError) {
return WrappedAxios.handleError(error);
}

if (error.code != 'ECONNREFUSED' && error.code != "ETIMEDOUT" && error.code != "ENOTFOUND"){
return Promise.reject(error)
}


var hasDirectAccess = await this.transports.hasDirectAccess(preparedArgs.url);
var isDirectAccessRestricted = (torCtrl.settings.enabled2 === 'always');
var useDirectAccess = (hasDirectAccess && !isDirectAccessRestricted);
let isTorReady = this.transports.isTorReady();

if (isDirectAccessRestricted) {
isTorReady = await this.transports.waitTorReady();
}

var isTorEnabledInSettings = (torCtrl.settings.enabled2 !== 'neveruse');
var useTor = (!useDirectAccess && isTorReady && isTorEnabledInSettings);

const hasDirectAccess = await this.transports.hasDirectAccess(preparedArgs.url);
const isDirectAccessRestricted = (torCtrl.settings.enabled2 === 'always');
const useDirectAccess = (hasDirectAccess && !isDirectAccessRestricted);
const isTorReady = await this.transports.waitTorReady();
const isTorEnabledInSettings = (torCtrl.settings.enabled2 !== 'neveruse');
const useTor = (!useDirectAccess && isTorReady && isTorEnabledInSettings);

if (useTor) {
const isTorAutoEnabled = (torCtrl.settings.enabled2 === 'auto');
Expand Down Expand Up @@ -212,13 +224,18 @@ class WrappedFetch {
});
})
.catch(async (error) => {

const isAgentAttached = WrappedFetch.isAgentAttached(preparedArgs);
const isAgentError = this.transports.checkForAgentError(error);

if (isAgentAttached && isAgentError) {
return WrappedFetch.handleError(error);
}

if (error.code != 'ECONNREFUSED' && error.code != "ETIMEDOUT" && error.code != "ENOTFOUND"){
return Promise.reject(error)
}

const hasDirectAccess = await this.transports.hasDirectAccess(url);
const isDirectAccessRestricted = (torCtrl.settings.enabled2 === 'always');
const useDirectAccess = (hasDirectAccess && !isDirectAccessRestricted);
Expand Down Expand Up @@ -341,7 +358,13 @@ class WrappedRequest {
const hasDirectAccess = await this.transports.hasDirectAccess(url);
const isDirectAccessRestricted = (torCtrl.settings.enabled2 === 'always');
const useDirectAccess = (hasDirectAccess && !isDirectAccessRestricted);
const isTorReady = await this.transports.waitTorReady();

let isTorReady = this.transports.isTorReady();

if (isDirectAccessRestricted) {
isTorReady = await this.transports.waitTorReady();
}

const isTorEnabledInSettings = (torCtrl.settings.enabled2 !== 'neveruse');
const useTor = (!useDirectAccess && isTorReady && isTorEnabledInSettings);

Expand Down

0 comments on commit 7239695

Please sign in to comment.