src/Graviton/CoreBundle/Listener/JsonExceptionListener.php
private function decorateKnownCases($exception)
    {
        if (
            $exception instanceof \ErrorException &&
            strpos($exception->getMessage(), 'Undefined index: $id') !== false
        ) {
            return [
                'code' => $exception->getCode(),
                'message' => 'An incomplete internal MongoDB ref has been discovered that can not be rendered. '.
                    'Did you pass a select() RQL statement and shaved off on the wrong level? Try to select a level '.
                    'higher.'
            ];
        } elseif (
            $exception instanceof SerializationException &&
            strpos($exception->getMessage(), 'Cannot serialize content class') !== false
        ) {
            $error = $exception->getMessage();
            $message =  strpos($error, 'not be found.') !== false ?
                substr($error, 0, strpos($error, 'not be found.')).'not be found.' : $error;
            preg_match('/\bwith id: (.*);.*?\bdocument\\\(.*)".*?\bidentifier "(.*)"/is', $message, $matches);
            if (array_key_exists(3, $matches)) {
                $sentence = 'Internal Database reference error as been discovered. '.
                    'The object id: "%s" has a reference to document: "%s" with id: "%s" that could not be found.';
                $message = sprintf($sentence, $matches[1], $matches[2], $matches[3]);
            }
            return [
                'code' => $exception->getCode(),
                'message' => $message
            ];
        }
    }
private function decorateKnownCases($exception)
    {
        if (
            $exception instanceof \ErrorException &&
            strpos($exception->getMessage(), 'Undefined index: $id') !== false
        ) {
            return [
                'code' => $exception->getCode(),
                'message' => 'An incomplete internal MongoDB ref has been discovered that can not be rendered. '.
                    'Did you pass a select() RQL statement and shaved off on the wrong level? Try to select a level '.
                    'higher.'
            ];
        } elseif (
            $exception instanceof SerializationException &&
            strpos($exception->getMessage(), 'Cannot serialize content class') !== false
        ) {
            $error = $exception->getMessage();
            $message =  strpos($error, 'not be found.') !== false ?
                substr($error, 0, strpos($error, 'not be found.')).'not be found.' : $error;
            preg_match('/\bwith id: (.*);.*?\bdocument\\\(.*)".*?\bidentifier "(.*)"/is', $message, $matches);
            if (array_key_exists(3, $matches)) {
                $sentence = 'Internal Database reference error as been discovered. '.
                    'The object id: "%s" has a reference to document: "%s" with id: "%s" that could not be found.';
                $message = sprintf($sentence, $matches[1], $matches[2], $matches[3]);
            }
            return [
                'code' => $exception->getCode(),
                'message' => $message
            ];
        }
    }
private function decorateKnownCases ( $ exception ) { if ( $ exception instanceof \ ErrorException && strpos ( $ exception -> getMessage ( ) , 'Undefined index: $id' ) !== false ) { return [ 'code' => $ exception -> getCode ( ) , 'message' => 'An incomplete internal MongoDB ref has been discovered that can not be rendered. ' . 'Did you pass a select() RQL statement and shaved off on the wrong level? Try to select a level ' . 'higher.' ] ; } elseif ( $ exception instanceof SerializationException && strpos ( $ exception -> getMessage ( ) , 'Cannot serialize content class' ) !== false ) { $ error = $ exception -> getMessage ( ) ; $ message = strpos ( $ error , 'not be found.' ) !== false ? substr ( $ error , 0 , strpos ( $ error , 'not be found.' ) ) . 'not be found.' : $ error ; preg_match ( '/\bwith id: (.*);.*?\bdocument\\\(.*)".*?\bidentifier "(.*)"/is' , $ message , $ matches ) ; if ( array_key_exists ( 3 , $ matches ) ) { $ sentence = 'Internal Database reference error as been discovered. ' . 'The object id: "%s" has a reference to document: "%s" with id: "%s" that could not be found.' ; $ message = sprintf ( $ sentence , $ matches [ 1 ] , $ matches [ 2 ] , $ matches [ 3 ] ) ; } return [ 'code' => $ exception -> getCode ( ) , 'message' => $ message ] ; } }
Here we can pick up known cases that can happen and render a more detailed error message for the client.
It may be cumbersome, but it's good to detail error messages then just to let general error messages
generate support issues and work for us.

@param \Exception $exception exception

@return array|null either a error message array or null if the general should be displayed
Here we can pick up known cases that can happen and render a more detailed error message for the client . It may be cumbersome but it s good to detail error messages then just to let general error messages generate support issues and work for us .