Skip to content

Commit

Permalink
fix error response from watson api url
Browse files Browse the repository at this point in the history
will throw exception when there is error message from watson api
  • Loading branch information
anuj9196 authored Jun 18, 2018
1 parent cbc9026 commit 8060d4c
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/WatsonTts.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,25 @@ private function processWatsonTtsCurl()
curl_close($ch);
fclose($output_file);

if (filesize($this->output_file_path) < 1000) {
//
// probably there is an error and error string is saved to file,
// open file and read the string
// if error key exists in the string, delete generated file and throw exception
//
$content = file_get_contents($this->output_file_path);

$debug_content = json_decode($content);

if (key_exists('error', $debug_content)) {
// deleted file created, because it is currupt
unlink($this->output_file_path);
// throw exception of the returned error
throw new Exception($debug_content->description, $debug_content->code);
}

}

if ($result && is_file($this->output_file_path))
return $this->output_file_path;

Expand Down Expand Up @@ -282,4 +301,4 @@ private function _prepareVoice()
$this->use_voice = $this->language.'_'.$this->voice;
}

}
}

0 comments on commit 8060d4c

Please sign in to comment.