Skip to content

Commit

Permalink
Reuse an error behaviour across two pages #3263
Browse files Browse the repository at this point in the history
  • Loading branch information
LinaKind committed May 23, 2024
1 parent 9c18a57 commit 83b833a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 18 deletions.
7 changes: 6 additions & 1 deletion src/read-side/html-pages/create-page-from-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { toHtmlFragment } from '../../types/html-fragment';

export const toNotFound = (): ErrorPageBodyViewModel => toErrorPageBodyViewModel({
type: DE.notFound,
message: toHtmlFragment('Page not found'),
message: toHtmlFragment('Page not found.'),
});

export const toUnavailable = (): ErrorPageBodyViewModel => toErrorPageBodyViewModel({
type: DE.unavailable,
message: toHtmlFragment('Sorry, something went wrong. Please try again later.'),
});

type GeneratePage<P> = (params: P) => TE.TaskEither<ErrorPageBodyViewModel, HtmlPage>;
Expand Down
12 changes: 3 additions & 9 deletions src/read-side/html-pages/groups-page/groups-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,19 @@ import { pipe } from 'fp-ts/function';
import { constructViewModel } from './construct-view-model/construct-view-model';
import { Dependencies } from './construct-view-model/dependencies';
import { renderGroups } from './render-groups';
import * as DE from '../../../types/data-error';
import { ErrorPageBodyViewModel, toErrorPageBodyViewModel } from '../../../types/error-page-body-view-model';
import { toHtmlFragment } from '../../../types/html-fragment';
import { ErrorPageBodyViewModel } from '../../../types/error-page-body-view-model';
import { toUnavailable } from '../create-page-from-params';
import { HtmlPage, NotHtml, toHtmlPage } from '../html-page';
import { renderGroupCard } from '../shared-components/group-card';

const renderErrorPage = (error: DE.DataError): ErrorPageBodyViewModel => toErrorPageBodyViewModel({
type: error,
message: toHtmlFragment('We\'re having trouble accessing search right now, please try again later.'),
});

type GroupsPage = TE.TaskEither<ErrorPageBodyViewModel, HtmlPage>;

export const groupsPage = (dependencies: Dependencies): GroupsPage => pipe(
constructViewModel(dependencies),
TE.map(RA.map(renderGroupCard)),
TE.map(renderGroups),
TE.bimap(
renderErrorPage,
toUnavailable,
(content) => toHtmlPage({
title: 'Groups',
content,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@ import { constructViewModel } from './construct-view-model';
import { Dependencies } from './dependencies';
import { paramsCodec } from './params';
import { renderAsHtml } from './render-as-html';
import * as DE from '../../../types/data-error';
import { toErrorPageBodyViewModel } from '../../../types/error-page-body-view-model';
import { toHtmlFragment } from '../../../types/html-fragment';
import { ConstructPage } from '../construct-page';

const toUnavailable = () => toErrorPageBodyViewModel({
type: DE.unavailable,
message: toHtmlFragment('Sorry, something went wrong. Please try again later.'),
});
import { toUnavailable } from '../create-page-from-params';

export const saveArticleFormPage = (
dependencies: Dependencies,
Expand Down

0 comments on commit 83b833a

Please sign in to comment.