Skip to content

Commit

Permalink
fix(tasks): update axios error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Jan 2, 2024
1 parent a4f7ffd commit 684fbe2
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions apps/tasks/src/queries/driveUpload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios from 'axios';
import axios, { type AxiosError } from 'axios';
import { ChildProcessWithoutNullStreams, spawn } from 'child_process';
import config from 'config';
import { drive_v3, google } from 'googleapis';
import type { ClientRequest } from 'http';
import { createReadStream } from 'node:fs';
import * as fs from 'node:fs/promises';
import { tmpdir } from 'node:os';
Expand Down Expand Up @@ -340,10 +341,21 @@ export async function driveUpload({
return { error: 'unknown_service', notify: false };
}
} catch (e) {
logger.error(`Error in uploading recording ${recordingId} for user ${userId}`, e);
logger.error(`Error in uploading recording ${recordingId} for user ${userId}`);
await clearReadyState(recordingId);
if (child) killProcessTree(child);
if (tempFile) await fs.unlink(tempFile).catch(() => {});
if ((e as AxiosError).isAxiosError === true) {
const response = (e as AxiosError).response;
const request: ClientRequest = (e as AxiosError).request;
if (response)
logger.error(
`AxiosError (${response.status}) ${request ? `${request.method} ${request.host}${request.path}` : '<unknown request>'}`,
response.data
);
else if (request) logger.error(`AxiosError <unknown response> ${request.method} ${request.host}${request.path}`);
else console.error(e);
}
return { error: (e as any).toString() || 'unknown_error', notify: true };
}
}

0 comments on commit 684fbe2

Please sign in to comment.