private static function imagesApplicationErrorToException($error) {
    switch($error->getApplicationError()) {
      case ImagesServiceError\ErrorCode::UNSPECIFIED_ERROR:
        $result = new CloudStorageException('Unspecified error with image.');
        break;
      case ImagesServiceError\ErrorCode::BAD_TRANSFORM_DATA:
        $result = new CloudStorageException('Bad image transform data.');
        break;
      case ImagesServiceError\ErrorCode::NOT_IMAGE:
        $result = new CloudStorageException('Not an image.');
        break;
      case ImagesServiceError\ErrorCode::BAD_IMAGE_DATA:
        $result = new CloudStorageException('Bad image data.');
        break;
      case ImagesServiceError\ErrorCode::IMAGE_TOO_LARGE:
        $result = new CloudStorageException('Image too large.');
        break;
      case ImagesServiceError\ErrorCode::INVALID_BLOB_KEY:
        $result = new CloudStorageException('Invalid blob key for image.');
        break;
      case ImagesServiceError\ErrorCode::ACCESS_DENIED:
        $result = new CloudStorageException('Access denied to image.');
        break;
      case ImagesServiceError\ErrorCode::OBJECT_NOT_FOUND:
        $result = new CloudStorageException('Image object not found.');
        break;
      default:
        $result = new CloudStorageException(
            'Images Error Code: ' . $error->getApplicationError());
    }
    return $result;
  }