def agi_code_check(code, response, line):
    """
    Check the AGI code and return a dict to help on error handling.
    """
    result = {'status_code': code, 'result': ('', ''), 'msg': ''}
    if code == 200:
        for key, value, data in re_kv.findall(response):
            result[key] = (value, data)
            # If user hangs up... we get 'hangup' in the data
            if data == 'hangup':
                return {'error': 'AGIResultHangup', 'msg': 'User hungup during execution'}
            if key == 'result' and value == '-1':
                return {'error': 'AGIAppError', 'msg': 'Error executing application, or hangup'}
        return result
    elif code == 510:
        result['error'] = 'AGIInvalidCommand'
        return result
    elif code == 520:
        usage = [line]
        usage = '%s\n' % '\n'.join(usage)
        # AGI Usage error
        result['error'] = 'AGIUsageError'
        result['msg'] = 'usage'
        return result
    else:
        # Unhandled code or undefined response
        result['error'] = 'AGIUnknownError'
        return result
dataset/ETHPy150Open gawel/panoramisk/panoramisk/utils.py/agi_code_check/original