hide unexpected error message from ui, still can be seen in console
This commit is contained in:
@@ -81,7 +81,9 @@ const fetcher = methods.reduce<Partial<FetcherObject>>((acc, method) => {
|
||||
try {
|
||||
err = JSON.parse(text);
|
||||
} catch (e) {
|
||||
throw text;
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(err);
|
||||
throw 'Something went wrong.';
|
||||
}
|
||||
throw err;
|
||||
});
|
||||
|
||||
@@ -12,7 +12,7 @@ import { StaticStore } from '@app/common/static_store';
|
||||
import debounce from '@app/utils/debounce';
|
||||
import copy from '@app/common/copy';
|
||||
import { Theme, BlockTTL, Comment as CommentType, PostInfo, User, CommentMode, Image } from '@app/common/types';
|
||||
import { extractErrorMessageFromResponse, FetcherResponse } from '@app/utils/errorUtils';
|
||||
import { extractErrorMessageFromResponse, FetcherError } from '@app/utils/errorUtils';
|
||||
|
||||
import { Input } from '@app/components/input';
|
||||
import { AvatarIcon } from '@app/components/avatar-icon';
|
||||
@@ -213,7 +213,7 @@ export class Comment extends Component<Props, State> {
|
||||
}
|
||||
}
|
||||
|
||||
handleVoteError(e: FetcherResponse, originalScore: number, originalDelta: number) {
|
||||
handleVoteError(e: FetcherError, originalScore: number, originalDelta: number) {
|
||||
this.setState({
|
||||
scoreDelta: originalDelta,
|
||||
cachedScore: originalScore,
|
||||
|
||||
@@ -20,14 +20,15 @@ const errorMessageForCodes = new Map([
|
||||
[18, 'Requested file cannot be found.'],
|
||||
]);
|
||||
|
||||
export type FetcherResponse =
|
||||
export type FetcherError =
|
||||
| string
|
||||
| {
|
||||
code?: number;
|
||||
details?: string;
|
||||
error: string;
|
||||
};
|
||||
|
||||
export function extractErrorMessageFromResponse(response: FetcherResponse): string {
|
||||
export function extractErrorMessageFromResponse(response: FetcherError): string {
|
||||
const defaultErrorMessage = 'Something went wrong. Please try again a bit later.';
|
||||
if (!response) {
|
||||
return defaultErrorMessage;
|
||||
|
||||
Reference in New Issue
Block a user