<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def build_error(self, err):
 """ When an exception is encountered, this generates a JSON error message for display to the user. :param err: The exception seen. The message is exposed to the user, so beware of sensitive data leaking. :type err: Exception :returns: A response object """

        data = {
            'error': err.args[0],
        }

        if self.is_debug():
            # Add the traceback.
            data['traceback'] = format_traceback(sys.exc_info())

        body = self.serializer.serialize(data)
        status = getattr(err, 'status', 500)
        return self.build_response(body, status=status)