🐛 (nordigen) bank-list error handling (#969)

Improving error handling for Nordigen.

Before: if loading banks failed - a loading indicator would be shown
forever.

After: is loading banks fails - an error message is shown.
This commit is contained in:
Matiss Janis Aboltins
2023-05-01 18:32:48 +01:00
committed by GitHub
parent 2d26cf3ad1
commit 977296361c
2 changed files with 33 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
import React, { useEffect, useState, useRef } from 'react';
import { send } from 'loot-core/src/platform/client/fetch';
import { send, sendCatch } from 'loot-core/src/platform/client/fetch';
import AnimatedLoading from '../../icons/AnimatedLoading';
import { colors } from '../../style';
@@ -14,9 +14,12 @@ import { COUNTRY_OPTIONS } from './countries';
function useAvailableBanks(country) {
const [banks, setBanks] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
useEffect(() => {
async function fetch() {
setIsError(false);
if (!country) {
setBanks([]);
setIsLoading(false);
@@ -25,9 +28,15 @@ function useAvailableBanks(country) {
setIsLoading(true);
const results = await send('nordigen-get-banks', country);
const { data, error } = await sendCatch('nordigen-get-banks', country);
if (error) {
setIsError(true);
setBanks([]);
} else {
setBanks(data);
}
setBanks(results);
setIsLoading(false);
}
@@ -37,6 +46,7 @@ function useAvailableBanks(country) {
return {
data: banks,
isLoading,
isError,
};
}
@@ -86,8 +96,11 @@ export default function NordigenExternalMsg({
let [error, setError] = useState(null);
let data = useRef(null);
const { data: bankOptions, isLoading: isBankOptionsLoading } =
useAvailableBanks(country);
const {
data: bankOptions,
isLoading: isBankOptionsLoading,
isError: isBankOptionError,
} = useAvailableBanks(country);
const { configured: isConfigured, isLoading: isConfigurationLoading } =
useNordigenStatus();
@@ -134,7 +147,13 @@ export default function NordigenExternalMsg({
/>
</FormField>
{country &&
{isBankOptionError ? (
<Error>
Failed loading available banks: Nordigen access credentials might be
misconfigured. Please set them up again.
</Error>
) : (
country &&
(isBankOptionsLoading ? (
'Loading banks...'
) : (
@@ -153,7 +172,8 @@ export default function NordigenExternalMsg({
}}
/>
</FormField>
))}
))
)}
<Warning>
By enabling bank-sync, you will be granting Nordigen (a third party

View File

@@ -0,0 +1,6 @@
---
category: Bugfix
authors: [MatissJanis]
---
Nordigen: improved error handling when bank-list API fails