Skip to content

Commit 47ead33

Browse files
authored
Merge pull request #1551 from Northeastern-Electric-Racing/#1550-display-google-errors-better
#1550 - Display Errors from Google API better
2 parents c2ebb7a + 046a347 commit 47ead33

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

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

Lines changed: 24 additions & 1 deletion
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();
@@ -101,7 +113,18 @@ export const uploadFile = async (fileObject: Express.Multer.File) => {
101113
const { id, name } = response.data;
102114
return { id, name };
103115
} catch (error: unknown) {
104-
if (error instanceof Error) {
116+
if ((error as GoogleDriveError).errors) {
117+
const gError = error as GoogleDriveError;
118+
throw new HttpException(
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+
)}`
126+
);
127+
} else if (error instanceof Error) {
105128
throw new HttpException(500, `Failed to Upload Receipt(s): ${error.message}`);
106129
}
107130
console.log('error' + error);

src/frontend/src/pages/FinancePage/ReimbursementRequestForm/ReimbursementRequestForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ const ReimbursementRequestForm: React.FC<ReimbursementRequestFormProps> = ({
159159
history.push(routes.FINANCE + '/' + reimbursementRequestId);
160160
} catch (e: unknown) {
161161
if (e instanceof Error) {
162-
toast.error(e.message, 3000);
162+
toast.error(e.message, 5000);
163163
}
164164
}
165165
};

0 commit comments

Comments
 (0)