From 95bc5ec6affd52655d8b9231d18deb6af017a04b Mon Sep 17 00:00:00 2001 From: Alfred Kamanda Date: Tue, 21 Oct 2025 15:49:02 +0300 Subject: [PATCH] set a different response content based on the API error code --- handlers/application/send.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/handlers/application/send.go b/handlers/application/send.go index 3580288..5e75cbe 100644 --- a/handlers/application/send.go +++ b/handlers/application/send.go @@ -2,6 +2,7 @@ package application import ( "context" + "errors" "fmt" "strconv" "strings" @@ -357,9 +358,20 @@ func (h *MenuHandlers) InitiateTransaction(ctx context.Context, sym string, inpu // Call TokenTransfer r, err := h.accountService.TokenTransfer(ctx, finalAmountStr, data.PublicKey, data.Recipient, data.ActiveAddress) if err != nil { + var apiErr *APIError + if errors.As(err, &apiErr) { + switch apiErr.Code { + case "E10": + res.Content = l.Get("Only USD vouchers are allowed to mpesa.sarafu.eth.") + default: + res.Content = l.Get("Your request failed. Please try again later.") + } + } else { + res.Content = l.Get("An unexpected error occurred. Please try again later.") + } + flag_api_error, _ := h.flagManager.GetFlag("flag_api_call_error") res.FlagSet = append(res.FlagSet, flag_api_error) - res.Content = l.Get("Your request failed. Please try again later.") logg.ErrorCtxf(ctx, "failed on TokenTransfer", "error", err) return res, nil }