The following exception is being thrown and not caught when an invalid Soundcloud URL is given:
GuzzleHttp\Exception\ClientException: Client error: `POST http://soundcloud.com/oembed?url=https%3A//soundcloud.com/hereandnowradio/grammy-winning-violist-kim&format=json` resulted in a `404 Not Found` response: in GuzzleHttp\Exception\RequestException::create() (line 111 of /Users/les.peabody/Sites/nec/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php).
The offending code is located between lines 69 and 97 in video_embed_soundcloud/src/Plugin/video_embed_field/Provider/Soundcloud.php:
try {
$data = (string) \Drupal::httpClient()->post($oembed_url)->getBody();
$json_decode_data = Json::decode($data);
if (isset($json_decode_data['html'])) {
$html_data = htmlentities($json_decode_data['html']);
$strip_data = strip_tags($html_data);
$decode_data = urldecode($strip_data);
$matches = explode("/", $decode_data);
if (count($matches) == 10) {
$track_array = explode("&", $matches[8]);
$track_id = $track_array[0];
$track_thumbnail = $track_id . "<>" . $json_decode_data['thumbnail_url'];
return $track_thumbnail;
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}
catch (Exception $ex) {
return FALSE;
}
The exception is uncaught because catch (Exception $ex) { is not referring to the correct exception class. It should instead be \Exception if you want to be as general as possible.
This has been marked critical since the uncaught Exception causes the entire request to die.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 2842828-GuzzleException.patch | 715 bytes | manojbisht_drupal |
| #3 | 2842828-GuzzleException.patch | 715 bytes | manojbisht_drupal |
| #2 | video_embed_soundcloud-invalid-url-uncaught-exception-2842828-2-D8.patch | 440 bytes | lpeabody |
Comments
Comment #2
lpeabody commentedPatch attached.
Comment #3
manojbisht_drupal commentedAbove patch solves, how exception is handled, however it doesnot describes how it should react, when wrong url is passed.
Attached patch solves above problem.
Comment #4
manojbisht_drupal commentedFixing patch again
Comment #6
manojbisht_drupal commented