* update dev deps * partial update dependencies * update watermelondb * update rn to 0.76.5, expo to 52.0.18 and others * upgrade android firebase * upgrade detox deps * fix package-lock.json * update emm and paste-input * update turbo-log * update network library * fix tests * review feedback * fix Keyboard blocking signIn button * Fall back to iphone 14 iOS 17.2 simulator as app crashes on iOS 17.4 * changes in deleteCredentialsForServer is causing a crash * withOptions x2 clearly is wrong * re-add cli-platform-apple fix * fix: RN 0.76.5 issue with bottom sheet disappearing (#8478) * experiment, using view vs BottomSheetView * revert previous & try disabling enableDynamicSizing * revert an unintended removal --------- Co-authored-by: yasserfaraazkhan <attitude3cena.yf@gmail.com> Co-authored-by: Mattermost Build <build@mattermost.com> Co-authored-by: Rahim Rahman <rahim.rahman@mattermost.com>
89 lines
2.4 KiB
TypeScript
89 lines
2.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import type {IntlShape} from 'react-intl';
|
|
|
|
export function isServerError(obj: unknown): obj is {server_error_id?: string} {
|
|
return (
|
|
typeof obj === 'object' &&
|
|
obj !== null &&
|
|
(
|
|
('server_error_id' in obj) &&
|
|
typeof obj.server_error_id === 'string'
|
|
)
|
|
);
|
|
}
|
|
|
|
export function isErrorWithMessage(obj: unknown): obj is {message: string} {
|
|
return (
|
|
typeof obj === 'object' &&
|
|
obj !== null &&
|
|
'message' in obj &&
|
|
typeof obj.message === 'string'
|
|
);
|
|
}
|
|
|
|
export function isErrorWithDetails(obj: unknown): obj is {details: Error} {
|
|
return (
|
|
typeof obj === 'object' &&
|
|
obj !== null &&
|
|
'details' in obj &&
|
|
typeof obj.details !== 'undefined'
|
|
);
|
|
}
|
|
|
|
export function isErrorWithIntl(obj: unknown): obj is {intl: ClientErrorIntl} {
|
|
return (
|
|
typeof obj === 'object' &&
|
|
obj !== null &&
|
|
'intl' in obj &&
|
|
typeof obj.intl === 'object' &&
|
|
obj.intl !== null
|
|
);
|
|
}
|
|
|
|
export function isErrorWithStatusCode(obj: unknown): obj is {status_code: number} {
|
|
return (
|
|
typeof obj === 'object' &&
|
|
obj !== null &&
|
|
'status_code' in obj &&
|
|
typeof obj.status_code === 'number'
|
|
);
|
|
}
|
|
|
|
export function isErrorWithUrl(obj: unknown): obj is {url?: string} {
|
|
return (
|
|
typeof obj === 'object' &&
|
|
obj !== null &&
|
|
('url' in obj) &&
|
|
typeof obj.url === 'string'
|
|
);
|
|
}
|
|
|
|
export const getFullErrorMessage = (error: unknown, intl?: IntlShape, depth = 0): string => {
|
|
const message = getErrorMessage(error, intl);
|
|
if (isErrorWithDetails(error)) {
|
|
if (depth > 2) {
|
|
return `${message}; ${getErrorMessage(error, intl)}`;
|
|
}
|
|
|
|
return `${message}; ${getFullErrorMessage(error.details, intl, depth + 1)}`;
|
|
}
|
|
|
|
return message;
|
|
};
|
|
|
|
export const getErrorMessage = (error: unknown, intl?: IntlShape) => {
|
|
if (typeof error === 'string') {
|
|
return error;
|
|
}
|
|
if (isErrorWithIntl(error)) {
|
|
return intl ? intl.formatMessage({id: error.intl.id, defaultMessage: error.intl.defaultMessage}, error.intl.values) : error.intl.defaultMessage!;
|
|
}
|
|
|
|
if (isErrorWithMessage(error)) {
|
|
return error.message;
|
|
}
|
|
|
|
return 'Unknown error';
|
|
};
|