Skip to content

Commit

Permalink
🔀 Merge pull request #1434 from TF2Autobot/revert-1171
Browse files Browse the repository at this point in the history
↩️ Partially revert changes made in #1171
  • Loading branch information
idinium96 authored Jan 2, 2023
2 parents 503772c + 977e33d commit 94b8480
Show file tree
Hide file tree
Showing 9 changed files with 548 additions and 375 deletions.
71 changes: 71 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
"@tf2autobot/tf2-schema": "^4.2.6",
"@tf2autobot/tf2-sku": "^2.0.3",
"@tf2autobot/tradeoffer-manager": "^2.14.1",
"async": "^3.2.4",
"axios": "^0.27.2",
"bluebird": "^3.7.2",
"bluebird-global": "^1.0.1",
"body-parser": "^1.20.0",
"callback-queue": "^3.0.0",
"change-case": "^4.1.2",
Expand Down Expand Up @@ -70,6 +73,8 @@
},
"devDependencies": {
"@babel/preset-typescript": "^7.18.6",
"@types/async": "^3.2.15",
"@types/bluebird-global": "^3.5.13",
"@types/cheerio": "^0.22.31",
"@types/death": "^1.1.2",
"@types/express": "^4.17.14",
Expand Down
72 changes: 34 additions & 38 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ if (process.env.BOT_VERSION !== pjson.version) {
process.exit(1);
}

import 'bluebird-global';

import dotenv from 'dotenv';

dotenv.config({ path: path.join(__dirname, '../.env') });
Expand Down Expand Up @@ -142,46 +144,40 @@ process.on('message', message => {
}
});

botManager
.start(options)
.then(async () => {
if (options.enableHttpApi) {
const { default: HttpManager } = await import('./classes/HttpManager');
const httpManager = new HttpManager(options);
await httpManager.start();
}
})
.catch(err => {
if (err) {
// https://stackoverflow.com/questions/30715367/why-can-i-not-throw-inside-a-promise-catch-handler
setTimeout(() => {
/*eslint-disable */
if (err.response || err.name === 'AxiosError') {
// if it's Axios error, filter the error

const e = new Error(err.message);

e['code'] = err.code;
e['status'] = err.response?.status ?? err.status;
e['method'] = err.config?.method ?? err.method;
e['url'] = err.config?.url?.replace(/\?.+/, '') ?? err.baseURL?.replace(/\?.+/, ''); // Ignore parameters

if (typeof err.response?.data === 'string' && err.response?.data?.includes('<html>')) {
return throwErr(e);
}
void botManager.start(options).asCallback(err => {
if (err) {
/*eslint-disable */
if (err.response || err.name === 'AxiosError') {
// if it's Axios error, filter the error

e['data'] = err.response?.data;
const e = new Error(err.message);

return throwErr(e);
}
/*eslint-enable */
e['code'] = err.code;
e['status'] = err.response?.status ?? err.status;
e['method'] = err.config?.method ?? err.method;
e['url'] = err.config?.url?.replace(/\?.+/, '') ?? err.baseURL?.replace(/\?.+/, ''); // Ignore parameters

if (typeof err.response?.data === 'string' && err.response?.data?.includes('<html>')) {
throw e;
}

e['data'] = err.response?.data;

return throwErr(err);
}, 10);
throw e;
}
});
/*eslint-enable */

function throwErr(err): void {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
process.emit('uncaughtException', err);
}
throw err;
}

if (options.enableHttpApi) {
void import('./classes/HttpManager').then(({ default: HttpManager }) => {
const httpManager = new HttpManager(options);
void httpManager.start().asCallback(err => {
if (err) {
throw err;
}
});
});
}
});
Loading

0 comments on commit 94b8480

Please sign in to comment.