public async Task <IActionResult> PreExchange([FromBody] PreExchangeModel request) { string merchantId = this.GetUserMerchantId(); try { var clientRequest = Mapper.Map <PreExchangeRequest>(request, opt => opt.Items["MerchantId"] = merchantId); ExchangeClientResponse response = await _payInternalClient.PreExchangeAsync(clientRequest); return(Ok(Mapper.Map <ExchangeResponse>(response))); } catch (DefaultErrorResponseException e) when(e.StatusCode == HttpStatusCode.BadRequest) { var apiException = e.InnerException as ApiException; if (apiException?.StatusCode == HttpStatusCode.BadRequest) { return(BadRequest(apiException.GetContentAs <ErrorResponse>())); } _log.Error(e, null, $"request:{request.ToJson()}"); return(BadRequest(ErrorResponse.Create(e.Message))); } }
public async Task <IActionResult> PreExchange([FromBody] PreExchangeModel request) { try { ExchangeResult exchangeResult = await _exchangeService.PreExchangeAsync(Mapper.Map <PreExchangeCommand>(request)); return(Ok(Mapper.Map <ExchangeResponse>(exchangeResult))); } catch (InvalidOperationException e) { _log.ErrorWithDetails(e, request); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (AssetPairUnknownException e) { _log.ErrorWithDetails(e, new { e.BaseAssetId, e.QuotingAssetId }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (ExchangeOperationNotSupportedException e) { _log.ErrorWithDetails(e, request); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (MultipleDefaultMerchantWalletsException e) { _log.ErrorWithDetails(e, new { e.AssetId, e.MerchantId, e.PaymentDirection }); return(BadRequest(ErrorResponse.Create(e.Message))); } catch (DefaultMerchantWalletNotFoundException e) { _log.ErrorWithDetails(e, new { e.AssetId, e.MerchantId, e.PaymentDirection }); return(BadRequest(ErrorResponse.Create(e.MerchantId))); } catch (InsufficientFundsException e) { _log.ErrorWithDetails(e, new { e.WalletAddress, e.AssetId }); return(BadRequest(ErrorResponse.Create(e.Message))); } }