class ApiErrorExtractor {

  public String toUserPresentableMessage(IOException e, @Nullable String action) {
    String message = "Internal server error";
    if (clientError(e)) {
      message = getErrorMessage(e);
    }
    return action == null
        ? message
        : String.format("Encountered an error while %s: %s", action, message);
  }

}