<commit_before>import { SagaIterator } from "redux-saga";
import { call, put } from "redux-saga/effects";
import Immutable = require("seamless-immutable");
import { ImmutableObject } from "seamless-immutable";
import actionCreatorFactory from "typescript-fsa";
import { reducerWithInitialState } from "typescript-fsa-reducers";

import { IBook } from "../lib/books";
import * as functions from "../lib/functions";
import { takeEvery } from "./utils";

const getBooks = actionCreatorFactory().async<void, IBook[]>("GET_BOOKS");

export const actionCreators = { getBooks: () => getBooks.started(null) };

export interface IState {
    books: IBook[] | null;
}

export const initialState: ImmutableObject<IState> = Immutable({ books: null });

export const reducer = reducerWithInitialState(initialState)
    .case(getBooks.done, (state, { result }) => state.merge({ books: result }));

export const sagas = [
    takeEvery(
        getBooks.started,
        function* getTasksSaga(): SagaIterator {
            yield put(getBooks.done({
                params: null,
                result: yield call(functions.call, "books"),
            }));
        }),
];<commit_msg>Catch network error<commit_after>import { SagaIterator } from "redux-saga";
import { call, put } from "redux-saga/effects";
import Immutable = require("seamless-immutable");
import { ImmutableObject } from "seamless-immutable";
import actionCreatorFactory from "typescript-fsa";
import { reducerWithInitialState } from "typescript-fsa-reducers";

import { IBook } from "../lib/books";
import * as functions from "../lib/functions";
import { takeEvery } from "./utils";

const getBooks = actionCreatorFactory().async<void, IBook[]>("GET_BOOKS");

export const actionCreators = { getBooks: () => getBooks.started(null) };

export interface IState {
    books: IBook[] | null;
}

export const initialState: ImmutableObject<IState> = Immutable({ books: null });

export const reducer = reducerWithInitialState(initialState)
    .case(getBooks.done, (state, { result }) => state.merge({ books: result }));

export const sagas = [
    takeEvery(
        getBooks.started,
        function* getTasksSaga(): SagaIterator {
            try {
                yield put(getBooks.done({
                    params: null,
                    result: yield call(functions.call, "books"),
                }));
            } catch (error) {
                console.error(error);
            }
        }),
];
{'fraction_non_alphanumeric': 0.13658536585365855, 'fraction_numerical': 0.0, 'mean_word_length': 3.3175438596491227, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4588094', 'n_tokens_mistral': 728, 'n_tokens_neox': 710, 'n_words': 176}