Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import timeout from 'connect-timeout';

const app = express();
const PORT = process.argv[2] || 56666;
const maxErrorHandlingCount = 10;
let errorHandlingCount = 0;
// const maxErrorHandlingCount = 10;
// let errorHandlingCount = 0;

const errorHandler = (
err: any,
Expand All @@ -25,8 +25,11 @@ const errorHandler = (
});
}

services.initApi();
logger.warn('📡 [global]: Connection reinitialized.');
// services.initApi();
// logger.warn('📡 [global]: Connection reinitialized.');
logger.warn('📡 [global]: Apps go to reload.');
// eslint-disable-next-line no-process-exit
process.exit(1);
};

const loggingResponse = (_: Request, res: Response, next: NextFunction) => {
Expand Down Expand Up @@ -65,15 +68,15 @@ app.post('/api/v1/swork/workreport', services.swork.reportWorks);
app.use(errorHandler);
process.on('uncaughtException', (err: Error) => {
logger.error(`☄️ [global] Uncaught exception ${err.message}`);
if (++errorHandlingCount <= maxErrorHandlingCount) {
errorHandler(err, null, null, null);
} else {
logger.error(
'Reach max error handling count, just exit and waitinng for restart'
);
// eslint-disable-next-line no-process-exit
process.exit(1);
}
// if (++errorHandlingCount <= maxErrorHandlingCount) {
// errorHandler(err, null, null, null);
// } else {
// logger.error(
// 'Reach max error handling count, just exit and waitinng for restart'
// );
// }
// eslint-disable-next-line no-process-exit
process.exit(1);
});

app.listen(PORT, () => {
Expand Down
10 changes: 8 additions & 2 deletions src/services/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ export async function sendTx(tx: SubmittableExtrinsic, krp: KeyringPair) {
` ↪ 💸 [tx]: Transaction status: ${status.type}, nonce: ${tx.nonce}`
);

if (status.isInvalid || status.isDropped || status.isUsurped) {
if (
status.isInvalid ||
status.isDropped ||
status.isUsurped ||
status.isRetracted
) {
reject(new Error(`${status.type} transaction.`));
} else {
// Pass it
}

if (status.isInBlock) {
if (status.isFinalized) {
events.forEach(({event: {data, method, section}}) => {
if (section === 'system' && method === 'ExtrinsicFailed') {
const [dispatchError] = data as unknown as ITuple<[DispatchError]>;
Expand Down Expand Up @@ -85,6 +90,7 @@ export function queryToObj(queryRes: any) {

export async function withApiReady(fn: Function, next: NextFunction) {
const api = getApi();
await sleep(1000);
if (!api || !api.isConnected) {
next(new Error('⚠️ Chain is offline, please connect a running chain.'));
return;
Expand Down