I am trying to create three teir web applications:
So, I really want:
- AnboundularJS Frontend, which calls my "API exposure level"
- This "API exposure level" calls my API / web service.
- The API / Webservice stores the data in the database and then sends OK / Error to the "API Exposure Level"
- "API exposure level" transfers information to the external interface to update / show errors if necessary
The problem I am facing is that Guzzle in my āAPI Exposure Levelā overrides a message sent from an API / Webservice with its own generic messages, which are completely useless for my interface.
Example:
{
"code": 500,
"message": "Server error: 500"
}
instead of what API / Webservice is output
{
"code":500,
"message":"Token already exists"
}
My question is: how to get the original API / Webservice messages from buzzing instead of general ones?
Here is my API / Webservice controller method:
public function postAppTokensAction($guid)
{
$request = $this->get('request');
if (!$request->request->get('key')) {
throw new HttpException(500, 'Missing Key');
}
if (!$request->request->get('secret')) {
throw new HttpException(500, 'Missing Secret');
}
$repository = $this->getDoctrine()
->getRepository('AppBundle:App');
$app = $repository->findOneByGuid($guid);
$token = new Token();
$token->setKey($request->request->get('key'));
$token->setSecret($request->request->get('secret'));
$token->setApp($app);
try {
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($token);
$entityManager->flush();
return $app;
} catch(\Exception $e) {
throw new HttpException(500, "Token allready exists");
}
}
Here is my "API Exposure Level":
public function postAppTokensAction($guid)
{
$client = $this->get('guzzle.client.ws_app');
try {
$response = $client->request('POST', '/apps/' . $guid . '/tokens', [
'json' => [
'key' => '123',
'secret' => '123'
]
]);
} catch (Exception $e) {
}
return json_decode($response->getBody(), true);
}
Edit:
I donāt think the Guzzle Exception is a duplicate, because it has changed for the older version of Guzzle and the syntax.
I tried adding http_errors => false:
try {
$response = $client->request('POST', '/apps/' . $guid . '/tokens', [
'http_errors' => false,
'json' => [
'key' => '12345555',
'secret' => '123'
]
]);
} catch (\Exception $e) {
die($e);
}
return json_decode($response->getBody(), true);
, catch .