code: def handle_job_exception(self, exception, variables=None):
          
          # Get the error and traceback if we can
          # noinspection PyBroadException
          try:
              error_str, traceback_str = six.text_type(exception), traceback.format_exc()
          except Exception:
              self.metrics.counter('server.error.error_formatting_failure').increment()
              error_str, traceback_str = 'Error formatting error', traceback.format_exc()
          # Log what happened
          self.logger.exception(exception)
          if not isinstance(traceback_str, six.text_type):
              try:
                  # Try to
                  traceback_str = traceback_str.decode('utf-8')
              except UnicodeDecodeError:
                  traceback_str = 'UnicodeDecodeError: Traceback could not be decoded'
          # Make a bare bones job response
          error_dict = {
              'code': ERROR_CODE_SERVER_ERROR,
              'message': 'Internal server error: %s' % error_str,
              'traceback': traceback_str,
          }
  
          if variables is not None:
              # noinspection PyBroadException
              try:
                  error_dict['variables'] = {key: repr(value) for key, value in variables.items()}
              except Exception:
                  self.metrics.counter('server.error.variable_formatting_failure').increment()
                  error_dict['variables'] = 'Error formatting variables'
  
          return JobResponse(errors=[error_dict])
docs: Makes and returns a last-ditch error response.
  
          :param exception: The exception that happened
          :type exception: Exception
          :param variables: A dictionary of context-relevant variables to include in the error response
          :type variables: dict
  
          :return: A `JobResponse` object
          :rtype: JobResponse