* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ class RetailcrmExceptionMiddleware implements RetailcrmMiddlewareInterface { /** * {@inheritDoc} */ public function __invoke(RetailcrmApiRequest $request, callable $next = null) { try { $response = $next($request); } catch (Exception $e) { RetailcrmLogger::writeCaller($request->getMethod(), $e->getMessage()); RetailcrmLogger::writeNoCaller($e->getTraceAsString()); $response = new RetailcrmApiResponse(500, json_encode([ 'success' => false, 'errorMsg' => sprintf('Internal error: %s', $e->getMessage()), ])); } return $response; } }