namespace seekat;
use Countable;
+use Exception;
use Generator;
use http\{
Client,
}
/* fetch resource, unless already localized, and try for {$method}_url */
- return $this->$method->get(...$args)->otherwise(function(Throwable $error) use($method, $args) {
+ return $this->$method->get(...$args)->otherwise(function($error) use($method, $args) {
+ if ($error instanceof Throwable) {
+ $message = $error->getMessage();
+ } else {
+ $message = $error;
+ $error = new Exception($error);
+ }
if ($this->exists($method."_url", $url)) {
- $this->__log->info(__FUNCTION__."($method): ". $error->getMessage(), [
+ $this->__log->info(__FUNCTION__."($method): ". $message, [
"url" => (string) $this->__url
]);
return $this->withUrl($url)->get(...$args);
}
- $this->__log->error(__FUNCTION__."($method): ". $error->getMessage(), [
+ $this->__log->error(__FUNCTION__."($method): ". $message, [
"url" => (string) $this->__url
]);
});
$client->attach($this);
- $client->enqueue($request);
+ $client->enqueue($request, function(Response $response) {
+ $this->response = $response;
+ $this->complete(
+ [$this, "resolve"],
+ [$this, "reject"]
+ );
+ return true;
+ });
/* start off */
$client->once();
}
}
$this->notify((object) compact("client", "request", "progress"));
-
- if ($progress->info === "finished") {
- $this->response = $this->client->getResponse();
- $this->complete(
- [$this, "resolve"],
- [$this, "reject"]
- );
- }
}
/**
$reject($e);
}
} else {
- $reject($this->client->getTransferInfo($this->request)["error"]);
+ $reject($this->client->getTransferInfo($this->request)->error);
}
-
- $this->client->dequeue($this->request);
}
/**