public function testHandleRPCException() { $this->endpoint->expects($this->once())->method('call')->willThrowException(new \Exception('foo', 129)); $request = new AMQPMessage('{}', ['reply_to' => 'foo']); $request->delivery_info['routing_key'] = 'boo'; $reply = $this->handler->handle($request); $this->assertNotNull($reply); $this->assertTrue($reply->has('application_headers')); $headers = $reply->get('application_headers')->getNativeData(); $this->assertArrayHasKey('x-error', $headers); $this->assertEquals('foo', $headers['x-error']); $this->assertArrayHasKey('x-error-code', $headers); $this->assertEquals(129, $headers['x-error-code']); }
/** * @param AMQPMessage $message * * @return AMQPMessage|null * * @throws \Exception */ public function handle(AMQPMessage $message) { $request = $this->createRequest($message); if (!$message->has('reply_to')) { $this->endpoint->publish($request); return; } try { $response = $this->endpoint->call($request)->resolve(); } catch (\Exception $e) { $response = new Response('', ['x-error' => $e->getMessage(), 'x-error-code' => $e->getCode()]); } $reply = $this->createReply($response); if ($message->has('correlation_id')) { $reply->set('correlation_id', $message->get('correlation_id')); } return $reply; }