satellite/{web,console}: return empty payments list on no wallet error

This change modifies wallet payments endpoints to return empty lists
instead of returning a 404 error if a wallet is not found for a user.

Change-Id: Ic765fecbc8183d14f179ce1d510ae512d8e0c4a9
This commit is contained in:
Wilfred Asomani 2023-10-03 14:53:07 +00:00
parent 512e063a79
commit 2e87df380d
2 changed files with 16 additions and 11 deletions

View File

@ -517,12 +517,19 @@ func (p *Payments) WalletPayments(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
walletPayments, err := p.service.Payments().WalletPayments(ctx)
var walletPayments console.WalletPayments
walletPayments, err = p.service.Payments().WalletPayments(ctx)
if err != nil {
if console.ErrUnauthorized.Has(err) {
p.serveJSONError(ctx, w, http.StatusUnauthorized, err)
return
}
if errs.Is(err, billing.ErrNoWallet) {
if err = json.NewEncoder(w).Encode(walletPayments); err != nil {
p.log.Error("failed to encode payments", zap.Error(ErrPaymentsAPI.Wrap(err)))
}
return
}
p.serveJSONError(ctx, w, http.StatusInternalServerError, err)
return
@ -547,6 +554,12 @@ func (p *Payments) WalletPaymentsWithConfirmations(w http.ResponseWriter, r *htt
p.serveJSONError(ctx, w, http.StatusUnauthorized, err)
return
}
if errs.Is(err, billing.ErrNoWallet) {
if err = json.NewEncoder(w).Encode([]string{}); err != nil {
p.log.Error("failed to encode payments", zap.Error(ErrPaymentsAPI.Wrap(err)))
}
return
}
p.serveJSONError(ctx, w, http.StatusInternalServerError, err)
return

View File

@ -273,12 +273,7 @@ export class PaymentsHttpApi implements PaymentsApi {
const path = `${this.ROOT_PATH}/wallet/payments`;
const response = await this.client.get(path);
const json = await response.json();
if (!response.ok) {
if (json.error.includes('wallet does not exist')) {
// wallet does not exist automatically means that there are no payments
return [];
}
throw new APIError({
status: response.status,
message: 'Can not list token payment history',
@ -286,6 +281,7 @@ export class PaymentsHttpApi implements PaymentsApi {
});
}
const json = await response.json();
if (!json) return [];
if (json.payments) {
return json.payments.map(item =>
@ -315,15 +311,11 @@ export class PaymentsHttpApi implements PaymentsApi {
const path = `${this.ROOT_PATH}/wallet/payments-with-confirmations`;
const response = await this.client.get(path);
const json = await response.json();
if (!response.ok) {
if (json.error.includes('wallet does not exist')) {
// wallet does not exist automatically means that there are no payments
return [];
}
throw new Error('Can not list token payment with confirmations');
}
const json = await response.json();
if (json && json.length) {
return json.map(item =>
new PaymentWithConfirmations(