def get(account: str, request: Request) -> Response: if request.GET.get("account") and account != request.GET.get("account"): return render_error_response( _("The account specified does not match authorization token"), status_code=403, ) elif request.GET.get("id") and ( request.GET.get("account") or request.GET.get("memo") or request.GET.get("memo_type") ): return render_error_response( _( "requests with 'id' cannot also have 'account', 'memo', or 'memo_type'" ) ) try: # validate memo and memo_type make_memo(request.GET.get("memo"), request.GET.get("memo_type")) except ValueError: return render_error_response(_("invalid 'memo' for 'memo_type'")) try: response_data = rci.get( { "id": request.GET.get("id"), "sep10_client_account": account, "account": request.GET.get("account"), "memo": request.GET.get("memo"), "memo_type": request.GET.get("memo_type"), "type": request.GET.get("type"), "lang": request.GET.get("lang"), } ) except ValueError as e: return render_error_response(str(e), status_code=400) except ObjectDoesNotExist as e: return render_error_response(str(e), status_code=404) try: validate_response_data(response_data) except ValueError: logger.exception( _("An exception was raised validating GET /customer response") ) return render_error_response( _("unable to process request."), status_code=500 ) return Response(response_data)
def get(account: str, request: Request) -> Response: if request.GET.get( "account") and account != request.GET.get("account"): return render_error_response( _("The account specified does not match authorization token"), status_code=403, ) elif not (request.GET.get("id") or request.GET.get("account")): return render_error_response( _("unable to identify a user without 'id' or 'account'")) elif request.GET.get("memo_type") and not request.GET.get("memo"): return render_error_response(_("missing 'memo' for 'memo_type'")) try: # validate memo and memo_type memo_str(request.GET.get("memo"), request.GET.get("memo_type")) except ValueError: return render_error_response(_("invalid 'memo' for 'memo_type'")) try: response_data = rci.get({ "id": request.GET.get("id"), "account": request.GET.get("account"), "memo": request.GET.get("memo"), "memo_type": request.GET.get("memo_type"), "type": request.GET.get("type"), "lang": request.GET.get("lang"), }) except ValueError as e: return render_error_response(str(e), status_code=400) try: validate_response_data(response_data) except ValueError: logger.exception( _("An exception was raised validating GET /customer response")) return render_error_response(_("unable to process request."), status_code=500) return Response(response_data)