private static function applicationErrorToException($error) {
    switch($error->getApplicationError()) {
      case ErrorCode::URL_TOO_LONG:
        $result = new \InvalidArgumentException(
            'The upload URL supplied was too long.');
        break;
      case ErrorCode::PERMISSION_DENIED:
        $result = new CloudStorageException('Permission Denied');
        break;
      case ErrorCode::ARGUMENT_OUT_OF_RANGE:
        $result = new \InvalidArgumentException($error->getMessage());
        break;
      default:
        $result = new CloudStorageException(
            'Error Code: ' . $error->getApplicationError());
    }
    return $result;
  }