I am working on a wordpress plugin that deals with an external API. I want to use a try/catch block for the API call but I am not sure if the way I am dealing with the return value is ok.
try {
$response = wp_remote_post($url,$args);
$communication_location = wp_remote_retrieve_header( $response, 'location' );
$communication_location_arr = explode('/', $communication_location);
$communication_id = end($communication_location_arr);
$response_code = wp_remote_retrieve_response_code($response);
}
catch (Exception $e){
throw new Exception('Something went wrong when trying to create the communication');
}
return array(0 => $response_code,1 => $communication_id);
Should the try block only contain the wp_remote_post call?