{"size": 2269, "ext": "js", "max_stars_repo_path": "src/javascript/request_ui_handler.js", "max_stars_repo_name": "Gabor132/PartyPep_Front", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/javascript/request_ui_handler.js", "max_issues_repo_name": "Gabor132/PartyPep_Front", "max_issues_repo_issues_event_min_datetime": "2020-11-25T21:12:15.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T10:51:56.000Z", "max_forks_repo_path": "src/javascript/request_ui_handler.js", "max_forks_repo_name": "Gabor132/PartyPep_Front", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 6, "max_forks_count": null, "avg_line_length": 34.3787878788, "max_line_length": 79, "alphanum_fraction": 0.7197003085}
const RequestUIHandler = {};

export { RequestUIHandler };

// This is here to allow logging warnings and errors via the console
/*eslint no-console: ["error", { allow: ["warn", "error", "info"] }] */
//
// Auxiliar to handle Responses and Errors from Axios
//
RequestUIHandler._genericRequestResponseHandler = function(storeState) {
  if (storeState !== undefined) {
    storeState.serviceResponseBar.showSnackbar = true;
    storeState.serviceResponseBar.isError = false;
    storeState.serviceResponseBar.error.status = "";
    storeState.serviceResponseBar.error.description = "Success";
  }
};

RequestUIHandler._getTokenRequestResponseHandler = function(storeState) {
  if (storeState !== undefined) {
    storeState.serviceResponseBar.showSnackbar = true;
    storeState.serviceResponseBar.isError = false;
    storeState.serviceResponseBar.error.status = "";
    storeState.serviceResponseBar.error.description = "Success";
  }
};

RequestUIHandler._genericRequestErrorHandler = function(error, storeState) {
  // TODO: Replace with error component
  if (storeState !== undefined) {
    storeState.serviceResponseBar.showSnackbar = true;
    storeState.serviceResponseBar.isError = true;
    if (typeof error.response !== undefined) {
      storeState.serviceResponseBar.error.status = error.response.status;
      if (
        error.response.statusText !== undefined &&
        error.response.statusText !== ""
      ) {
        storeState.serviceResponseBar.error.description =
          error.response.statusText;
      } else {
        storeState.serviceResponseBar.error.description =
          "Failed to retrieve data";
      }
    } else {
      storeState.serviceResponseBar.error.status = "";
      storeState.serviceResponseBar.error.description =
        "Failed to retrieve data";
    }
  }
};

RequestUIHandler._getSuccessFunction = function(onSuccess, storeState) {
  if (onSuccess === undefined) {
    return RequestUIHandler._genericRequestResponseHandler(storeState);
  }
  return onSuccess(storeState);
};

RequestUIHandler._getFailureFunction = function(onFailure, error, storeState) {
  if (onFailure === undefined) {
    return RequestUIHandler._genericRequestErrorHandler(error, storeState);
  }
  return onFailure(error, storeState);
};
