def write_error(self, status_code, **kwargs):
def get_exc_message(exception):<EOL><INDENT>return exception.log_message ifhasattr(exception, "<STR_LIT>") else str(exception)<EOL><DEDENT>self.clear()<EOL>self.set_status(status_code)<EOL>exception = kwargs["<STR_LIT>"][<NUM_LIT:1>]<EOL>if any(isinstance(exception, c) for c in [APIError, ValidationError]):<EOL><INDENT>if isinstance(exception, ValidationError):<EOL><INDENT>self.set_status(<NUM_LIT>)<EOL><DEDENT>self.fail(get_exc_message(exception))<EOL><DEDENT>else:<EOL><INDENT>self.error(<EOL>message=self._reason,<EOL>data=get_exc_message(exception) if self.settings.get("<STR_LIT>")<EOL>else None,<EOL>code=status_code<EOL>)<EOL><DEDENT>
Override of RequestHandler.write_error

        Calls ``error()`` or ``fail()`` from JSendMixin depending on which
        exception was raised with provided reason and status code.

        :type  status_code: int
        :param status_code: HTTP status code