<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_error(self, status_code, **kwargs):
 """Override `write_error` in order to output JSON errors :param status_code: the response's status code, e.g. 500 """

        http_error = _get_http_error(kwargs)
        if http_error:
            self.finish(self._error_template(status_code,
                                             http_error.errors,
                                             http_error.source))
        else:
            source = kwargs.get('source', getattr(options, 'name', None))
            # Slightly annoyed that have to rely on the internal self._reason
            # to deal with unhandled exceptions. On the dev version of
            # tornado self._reason is always set, while in the current version
            # a reason kwarg is passed down from `send_error` but not set
            # on the instance.
            reason = kwargs.get('reason', self._reason)
            self.finish(self._error_template(status_code, reason, source))