You are here

function brightcove_try in Brightcove Video Connect 7.7

Same name and namespace in other branches
  1. 7.6 brightcove.module \brightcove_try()

Catches exceptions when interacting with the brightcove wrapper lib.

This function serves as a bridge between the OO-style wrapper lib and the procedural Drupal 7 error handling.

Parameters

callable $try: A closure that interacts with the wrapper lib.

callable|NULL $catch: A clusure that is called when an error occours. Gets the exception as a parameter.

string|NULL $logtype: Log type identifier.

Return value

mixed The same as what $try returns on success, or what $catch returns on failure.

36 calls to brightcove_try()
ajax_brightcove_media_upload_callback in brightcove_media/brightcove_media.module
Ajax callback for upload form
BrightcoveClientEntityUIController::operationFormValidate in ./brightcove.client.inc
@inheritdoc
BrightcovePlaylistEntityController::delete in ./brightcove.playlist.inc
Overwrites DrupalDefaultEntityController::delete().
BrightcovePlaylistEntityController::save in ./brightcove.playlist.inc
Overwrites EntityAPIController::save().
brightcove_admin_embed_delete_form_submit in ./brightcove.player.inc
Submit handler for brightcove_admin_embed_delete_form().

... See full list

File

./brightcove.module, line 3354
Brightcove module is an integration layer between any modules using Brightcove API. It makes all necessary checks for the API and makes settings available to the user.

Code

function brightcove_try(callable $try, callable $catch = NULL, $logtype = NULL) {
  brightcove_load_lib();
  try {
    $result = $try();
    return $result;
  } catch (\Brightcove\API\Exception\APIException $ex) {
    drupal_set_message(t('Brightcove API call failed: %message', [
      '%message' => _brightcove_try_json_message($ex
        ->getResponseBody()) ?: $ex
        ->getMessage(),
    ]), 'error');
    watchdog_exception($logtype ?: 'brightcove_api', $ex);
    if ($catch) {
      return $catch($ex);
    }
  } catch (\Brightcove\API\Exception\AuthenticationException $ex) {
    drupal_set_message(t('Failed to authorize with Brightcove'), 'error');
    watchdog_exception($logtype ?: 'brightcove_auth', $ex);
    if ($catch) {
      return $catch($ex);
    }
  }
  return NULL;
}