hide unexpected error message from ui, still can be seen in console

This commit is contained in:
Vyrtsev Mikhail
2019-04-20 18:54:20 +03:00
parent 619e9fec3b
commit 1dd97d42a1
3 changed files with 8 additions and 5 deletions
+3 -1
View File
@@ -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;
});
+2 -2
View File
@@ -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,
+3 -2
View File
@@ -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;