/** * Data provider of responses for specific exceptions. * @return array */ public function exceptionResponseProvider() { $genericMessage = 'An error occurred.'; return [[new TooLargeException($genericMessage), rsp::error('FileSizeTooLarge', $genericMessage)], [new XMLSyntaxException($genericMessage), rsp::error('XmlSyntaxError', $genericMessage)], [new ElementNotFoundException('mockExpectedElement', 'mockFoundElement'), rsp::error('ElementNotFoundError', 'Expected mockExpectedElement, found mockFoundElement')], [new UnexpectedNamespaceException('mock:invalid:ns', array('mock:valid:ns')), rsp::error('XmlSyntaxError', 'Unexpected namespace "mock:invalid:ns", expected one of: mock:valid:ns')], [new UnexpectedRootElementException('mock-invalid-rootElement', 'mock-valid-rootElement'), rsp::error('XmlSyntaxError', 'Unexpected root element "mock-invalid-rootElement", expected mock-valid-rootElement')], [new SchemaValidationException('mock:ns'), rsp::error('XmlSyntaxError', 'The XML document does not validate with mock:ns')], [new TooManyItemsException(), rsp::error('TooManyItems', 'Too many items in your messages.')], [new SuspiciousContentException(), rsp::error('SuspectedContent', 'Suspicious content found. Account deactivated.')], [new EventNotFoundException($genericMessage), rsp::error('NotFound', 'Resource not found')], [new \InvalidArgumentException($genericMessage), rsp::error('UnexpectedFailure', $genericMessage)], [new \Exception($genericMessage), rsp::error('UnexpectedFailure', $genericMessage)]]; }
private function processEventRequest($callback) { $status = null; try { $rsp = $callback(); } catch (TooLargeException $e) { $rsp = rsp::error('FileSizeTooLarge', $e->getMessage()); } catch (XMLSyntaxException $e) { $rsp = rsp::error('XmlSyntaxError', $e->getMessage()); } catch (ElementNotFoundException $e) { $rsp = rsp::error('ElementNotFoundError', $e->getMessage()); } catch (UnexpectedNamespaceException $e) { $rsp = rsp::error('XmlSyntaxError', $e->getMessage()); } catch (UnexpectedRootElementException $e) { $rsp = rsp::error('XmlSyntaxError', $e->getMessage()); } catch (SchemaValidationException $e) { $rsp = rsp::error('XmlSyntaxError', $e->getMessage()); } catch (TooManyItemsException $e) { $rsp = rsp::error('TooManyItems', $e->getMessage()); } catch (SuspiciousContentException $e) { $rsp = rsp::error('SuspectedContent', $e->getMessage()); } catch (EventNotFoundException $e) { $status = Response::HTTP_NOT_FOUND; $rsp = rsp::error('NotFound', 'Resource not found'); } catch (\Exception $e) { $rsp = rsp::error('UnexpectedFailure', $e->getMessage()); } return $this->createResponse($rsp, $status); }