mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-15 20:33:47 +00:00
chore: cleanup directory structure
This commit is contained in:
committed by
Carlos Valente
parent
e6070e6efd
commit
b75b69c3b1
@@ -0,0 +1,39 @@
|
||||
// https://developers.google.com/calendar/api/guides/errors
|
||||
interface GoogleApiError {
|
||||
code: number;
|
||||
message: string;
|
||||
errors?: {
|
||||
message: string;
|
||||
domain: string;
|
||||
reason: string;
|
||||
}[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether an error is a Google API error
|
||||
*/
|
||||
function isGoogleApiError(error: any): error is GoogleApiError {
|
||||
return (
|
||||
typeof error === 'object' &&
|
||||
error !== null &&
|
||||
typeof error.code === 'number' &&
|
||||
Array.isArray(error.errors) &&
|
||||
typeof error.errors[0]?.reason === 'string' &&
|
||||
typeof error.errors[0]?.message === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract utility to handle a common error where a user imports an xlsx file instead of a Google Sheet
|
||||
*/
|
||||
export function catchCommonImportXlsxError(error: any) {
|
||||
if (
|
||||
isGoogleApiError(error) &&
|
||||
error.code === 400 &&
|
||||
Array.isArray(error.errors) &&
|
||||
error.errors[0].reason === 'failedPrecondition' &&
|
||||
error.errors[0].message === 'This operation is not supported for this document'
|
||||
) {
|
||||
throw new Error('Cannot read the linked file as a Google Sheet. It may be an .xlsx file instead.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user