Skip to content

Commit 046a347

Browse files
committed
#1550 - no anys
1 parent f0d7925 commit 046a347

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

src/backend/src/utils/google-integration.utils.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ export const sendMailToAdvisor = async (subject: string, text: string) => {
6666
}
6767
};
6868

69+
interface GoogleDriveErrorListError {
70+
domain: string;
71+
reason: string;
72+
message: string;
73+
}
74+
75+
interface GoogleDriveError {
76+
errors: GoogleDriveErrorListError[];
77+
code: number;
78+
message: string;
79+
}
80+
6981
//tutorial used to set this up: https://www.labnol.org/google-drive-api-upload-220412
7082
export const uploadFile = async (fileObject: Express.Multer.File) => {
7183
const bufferStream = new stream.PassThrough();
@@ -100,13 +112,17 @@ export const uploadFile = async (fileObject: Express.Multer.File) => {
100112
});
101113
const { id, name } = response.data;
102114
return { id, name };
103-
} catch (error: any) {
104-
if (error.errors) {
115+
} catch (error: unknown) {
116+
if ((error as GoogleDriveError).errors) {
117+
const gError = error as GoogleDriveError;
105118
throw new HttpException(
106-
error.code,
107-
`Failed to Upload Receipt(s): ${error.message}, ${error.errors.reduce((acc: any, curr: any) => {
108-
return acc + ' ' + curr.message + ' ' + curr.reason;
109-
}, '')}`
119+
gError.code,
120+
`Failed to Upload Receipt(s): ${gError.message}, ${gError.errors.reduce(
121+
(acc: string, curr: GoogleDriveErrorListError) => {
122+
return acc + ' ' + curr.message + ' ' + curr.reason;
123+
},
124+
''
125+
)}`
110126
);
111127
} else if (error instanceof Error) {
112128
throw new HttpException(500, `Failed to Upload Receipt(s): ${error.message}`);

0 commit comments

Comments
 (0)