Skip to content

Commit

Permalink
umputun#10 fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mavrin committed Feb 23, 2020
1 parent da94f26 commit 3b2a01c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion frontend/app/common/fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('fetcher', () => {
fail(data);
})
.catch(e => {
expect(e.code).toBe(500);
expect(e.code).toBe(0);
expect(e.error).toBe('Something went wrong.');
});
});
Expand Down
4 changes: 2 additions & 2 deletions frontend/app/common/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const fetcher = methods.reduce<Partial<FetcherObject>>((acc, method) => {
if (httpErrorMap.has(res.status)) {
const descriptor = httpErrorMap.get(res.status) || httpMessages.unexpectedError;
throw {
code: descriptor ? res.status : 500,
code: res.status,
error: descriptor.defaultMessage,
};
}
Expand All @@ -98,7 +98,7 @@ const fetcher = methods.reduce<Partial<FetcherObject>>((acc, method) => {
console.error(err);
}
throw {
code: 500,
code: 0,
error: httpMessages.unexpectedError.defaultMessage,
};
}
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/last-comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { BASE_URL, DEFAULT_LAST_COMMENTS_MAX, LAST_COMMENTS_NODE_CLASSNAME } fro
import { ListComments } from '@app/components/list-comments';
import { IntlProvider } from 'react-intl';
import { loadLocale } from './utils/loadLocale';
import { getLocale } from './utils/getLocale';

if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
Expand Down Expand Up @@ -57,7 +58,7 @@ async function init(): Promise<void> {
(node.dataset.max && parseInt(node.dataset.max, 10)) ||
remark_config.max_last_comments ||
DEFAULT_LAST_COMMENTS_MAX;
const locale = remark_config.locale || 'en';
const locale = getLocale(remark_config);
Promise.all([getLastComments(remark_config.site_id!, max), loadLocale(locale)]).then(([comments, messages]) => {
try {
render(
Expand Down
3 changes: 2 additions & 1 deletion frontend/app/remark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import loadPolyfills from '@app/common/polyfills';

import { IntlProvider } from 'react-intl';
import { loadLocale } from './utils/loadLocale';
import { getLocale } from './utils/getLocale';

import { createElement, render } from 'preact';
import { bindActionCreators } from 'redux';
Expand Down Expand Up @@ -64,7 +65,7 @@ async function init(): Promise<void> {
}
return memo;
}, {});
const locale = params.locale || `en`;
const locale = getLocale(params);
const messages = await loadLocale(locale).catch(() => ({}));
StaticStore.config = await api.getConfig();

Expand Down
4 changes: 4 additions & 0 deletions frontend/app/utils/getLocale.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { LastCommentsConfig } from '@app/common/config-types';
export function getLocale(params: { [key: string]: string } | LastCommentsConfig): string {
return params.locale || 'en';
}

0 comments on commit 3b2a01c

Please sign in to comment.