<commit_before>import _ from 'lodash';

import { pushPath } from 'redux-simple-router';

import ActionTypes from './actionTypes';
import * as WebAPI from './api';

export function addMessage(status, message) {
  return {
    type: ActionTypes.ADD_MESSAGE,
    payload: {
      status,
      message,
      id: _.uniqueId()
    }
  };
}

export function dismissMessage(id) {
  return {
    type: ActionTypes.DISMISS_MESSAGE,
    payload: id
  };
}

export function getMovie(id) {
  return (dispatch) => {
    WebAPI
    .getMovie(id).then(result => dispatch({
      type: ActionTypes.MOVIE_LOADED,
      payload: result.data
    }))
    .catch(() => {
      dispatch(addMessage("danger", "Sorry, no movie found"));
      dispatch(pushPath("/all/"));
    });
  }
}

export function addMovie(title) {
  return (dispatch) => {
    WebAPI
    .addMovie(title)
    .then(result => {
      dispatch(addMessage("success", "New movie added"));
      dispatch(pushPath(`/movie/${result.data.imdbID}/`));
    });
  }
}

export function deleteMovie(movie) {
  return (dispatch) => {
    dispatch(addMessage("info", "Movie deleted"));
    WebAPI.deleteMovie(movie)
  }
}<commit_msg>Add error msg<commit_after>import _ from 'lodash';

import { pushPath } from 'redux-simple-router';

import ActionTypes from './actionTypes';
import * as WebAPI from './api';

export function addMessage(status, message) {
  return {
    type: ActionTypes.ADD_MESSAGE,
    payload: {
      status,
      message,
      id: _.uniqueId()
    }
  };
}

export function dismissMessage(id) {
  return {
    type: ActionTypes.DISMISS_MESSAGE,
    payload: id
  };
}

export function getMovie(id) {
  return (dispatch) => {
    WebAPI
    .getMovie(id).then(result => dispatch({
      type: ActionTypes.MOVIE_LOADED,
      payload: result.data
    }))
    .catch(() => {
      dispatch(addMessage("danger", "Sorry, no movie found"));
      dispatch(pushPath("/all/"));
    });
  }
}

export function addMovie(title) {
  return (dispatch) => {
    WebAPI
    .addMovie(title)
    .then(result => {
      dispatch(addMessage("success", "New movie added"));
      dispatch(pushPath(`/movie/${result.data.imdbID}/`));
    })
    .catch(() => {
      dispatch(addMessage("danger", `Sorry, couldn't find the movie "${title}"`));
    });
  }
}

export function deleteMovie(movie) {
  return (dispatch) => {
    dispatch(addMessage("info", "Movie deleted"));
    WebAPI.deleteMovie(movie)
  }
}
{'fraction_non_alphanumeric': 0.15856150388230486, 'fraction_numerical': 0.0, 'mean_word_length': 3.1281618887015177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '1492098', 'n_tokens_mistral': 807, 'n_tokens_neox': 773, 'n_words': 164}