Closed bradfordcondon closed 5 years ago
$connection = new \EUtils();
try {
$connection->setPreview();
$parsed = $connection->get($db, $accession);
$form_state['values']['parsed'] = $parsed;
}
catch (\Exception $e) {
tripal_set_message($e, TRIPAL_ERROR);
return;
}
i think try/catch just doesn't behave how i think it would. It looks like the validator already handles it gracefully via try/catch....
ok. i've sussed hte problem. Our EUTils DOES check if the request was successful: if it wasn't it would throw an error, and it gets caught and we have no problems.
/**
* Check if the request is successful.
*
* @return bool
* TRUE for success.
*/
public function isSuccessful() {
$status = $this->status();
return $status >= 200 && $status <= 299;
}
Unfortunately, that's not what happens, because the response code is 200 for a "no records found" request. So it goes to the parser and the formatter with this empty, bad XML.
So instead, we need to look at the data and see if its an "ERROR" response object:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE eSummaryResult PUBLIC "-//NLM//DTD esummary assembly 20180216//EN" "https://eutils.ncbi.nlm.nih.gov/eutils/dtd/20180216/esummary_assembly.dtd">
<eSummaryResult>
<DocumentSummarySet status="OK">
<DbBuild>Build190205-2205.1</DbBuild>
<DocumentSummary uid="744358">
<error>cannot get document summary</error>
</DocumentSummary>
</DocumentSummarySet>
</eSummaryResult>
if we're lucky, all EUtils requests will return something with an error
tag, and that can be how we determine if the request was unsuccessful.
merged, thank you @almasaeed2010
attemping to add an assembly of 744358: this is invalid.
However hte formatter throws these errors:
I would bet we need the formatters to gracefully fail.