protected function exitWithInternalError( $errorMessage, $errorCode = 500 )
    {
        if ( eZModule::$useExceptions )
        {
            switch ( $errorCode )
            {
                case 403:
                    throw new ezpAccessDenied( $errorMessage );

                case 500:
                default:
                    throw new RuntimeException( $errorMessage, $errorCode );
            }
        }
        else
        {
            header( $_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error' );
            eZExecution::cleanup();
            eZExecution::setCleanExit();

            return new ezpKernelResult(
                json_encode(
                    array(
                        'error'        => $errorMessage,
                        'code'         => $errorCode
                    )
                )
            );
        }
    }