Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc Cleanup #4455

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,7 @@ export function CreateAccountModal({ upgradingAccountId }: CreateAccountProps) {
return;
}

if (upgradingAccountId == null) {
authorizeBank(dispatch);
} else {
authorizeBank(dispatch);
}
authorizeBank(dispatch);
};

const onConnectSimpleFin = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ export function SelectLinkedAccountsModal({
return;
}

const upgradingId =
chosenLocalAccountId !== addOnBudgetAccountOption.id &&
chosenLocalAccountId !== addOffBudgetAccountOption.id
? chosenLocalAccountId
: undefined;

// Finally link the matched account
if (syncSource === 'simpleFin') {
dispatch(
linkAccountSimpleFin({
externalAccount,
upgradingId:
chosenLocalAccountId !== addOnBudgetAccountOption.id &&
chosenLocalAccountId !== addOffBudgetAccountOption.id
? chosenLocalAccountId
: undefined,
upgradingId,
offBudget,
}),
);
Expand All @@ -96,11 +98,7 @@ export function SelectLinkedAccountsModal({
linkAccount({
requisitionId,
account: externalAccount,
upgradingId:
chosenLocalAccountId !== addOnBudgetAccountOption.id &&
chosenLocalAccountId !== addOffBudgetAccountOption.id
? chosenLocalAccountId
: undefined,
upgradingId,
offBudget,
}),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/bin/build-api
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ yarn tsc -p tsconfig.api.json --outDir ../api/@types/loot-core/
# Copy existing handwritten .d.ts files, as tsc doesn't move them for us
dest="../../api/@types/loot-core"
cd src
find . -type f -name "*.d.ts" | while read -r f
/usr/bin/find . -type f -name "*.d.ts" | while read -r f
do
d=$(dirname "${f}")
d="${dest}/${d}"
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/bin/build-browser
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mkdir -p "$DATA_DIR"
"$ROOT"/copy-migrations "$DATA_DIR"

cd "$DATA_DIR"
find * -type f | sort > ../data-file-index.txt
/usr/bin/find * -type f | sort > ../data-file-index.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd "$ROOT"

OUTPUT_HASH="[contenthash]"
Expand Down
4 changes: 3 additions & 1 deletion packages/loot-core/src/server/accounts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,9 @@ async function checkSecret(name: string) {

try {
return await get(serverConfig.BASE_SERVER + '/secret/' + name, {
'X-ACTUAL-TOKEN': userToken,
headers: {
'X-ACTUAL-TOKEN': userToken,
},
});
} catch (error) {
console.error(error);
Expand Down
48 changes: 26 additions & 22 deletions packages/loot-core/src/server/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,35 @@ import { PostError } from './errors';
import * as Platform from './platform';

function throwIfNot200(res: Response, text: string) {
if (res.status !== 200) {
if (res.status === 500) {
throw new PostError(res.status === 500 ? 'internal' : text);
}

const contentType = res.headers.get('Content-Type');
if (contentType.toLowerCase().indexOf('application/json') !== -1) {
const json = JSON.parse(text);
throw new PostError(json.reason);
}

// Actual Sync Server may be exposed via a tunnel (e.g. ngrok). Tunnel errors should be treated as network errors.
const tunnelErrorHeaders = ['ngrok-error-code'];
const tunnelError = tunnelErrorHeaders.some(header =>
res.headers.has(header),
);
//there are a few places where we return 204 (success, but no content)
//these should probably also not throw (along with other 2xx codes)
if (Math.floor(res.status / 100) === 2) {
return;
}

if (res.status === 500) {
throw new PostError('internal');
}

if (tunnelError) {
// Tunnel errors are present when the tunnel is active and the server is not reachable e.g. server is offline
// When we experience a tunnel error we treat it as a network failure
throw new PostError('network-failure');
}
const contentType = res.headers.get('Content-Type') ?? '';
if (contentType.toLowerCase().indexOf('application/json') !== -1) {
const json = JSON.parse(text);
throw new PostError(json.reason);
}

// Actual Sync Server may be exposed via a tunnel (e.g. ngrok). Tunnel errors should be treated as network errors.
const tunnelErrorHeaders = ['ngrok-error-code'];
const tunnelError = tunnelErrorHeaders.some(header =>
res.headers.has(header),
);

throw new PostError(text);
if (tunnelError) {
// Tunnel errors are present when the tunnel is active and the server is not reachable e.g. server is offline
// When we experience a tunnel error we treat it as a network failure
throw new PostError('network-failure');
}

throw new PostError(text);
}

export async function post(
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4455.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [rugulous]
---

Allow building on Windows, checking for secrets, and tidy up a few duplications along the way!