Skip to content

Commit 64bd6cd

Browse files
danieltigsePedro Aim
authored andcommitted
minor bug fixes
1 parent db9b6bd commit 64bd6cd

File tree

4 files changed

+53
-27
lines changed

4 files changed

+53
-27
lines changed

electron_app/src/database/DBEexporter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const exportNotEncryptDatabaseToFile = async ({ databasePath, outputPath }) => {
8888
saveToFile({ data: labels, filepath, mode: 'a' });
8989

9090
let userEmail;
91-
if (myAccount.recipientId) {
91+
if (myAccount && myAccount.recipientId) {
9292
userEmail = myAccount.email;
9393
} else {
9494
const firstAccount = accountsData.firstAccount;
@@ -263,7 +263,7 @@ const _exportEmailTable = async (db, userEmail) => {
263263
);
264264

265265
emailRows = [...emailRows, ...result];
266-
if (rows.length < SELECT_ALL_BATCH) {
266+
if (result.length < SELECT_ALL_BATCH) {
267267
shouldEnd = true;
268268
} else {
269269
offset += SELECT_ALL_BATCH;
@@ -641,7 +641,7 @@ const exportEmailTable = async accountId => {
641641
);
642642
});
643643
emailRows = [...emailRows, ...result];
644-
if (emailRows.length < SELECT_ALL_BATCH) {
644+
if (result.length < SELECT_ALL_BATCH) {
645645
shouldEnd = true;
646646
} else {
647647
offset += SELECT_ALL_BATCH;

email_mailbox/src/libs/signal.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ const decryptEmail = async ({
3434
accountRecipientId
3535
}) => {
3636
const { status, body } = await fetchEmailBody({ bodyKey, optionalToken });
37-
if (status !== 200) return;
37+
if (status !== 200) {
38+
throw new Error(CONTENT_NOT_AVAILABLE);
39+
}
3840
if (typeof deviceId !== 'number' && typeof messageType !== 'number') {
3941
return { decryptedBody: body.body };
4042
}
@@ -51,10 +53,12 @@ const decryptEmail = async ({
5153
fileKeys: fileKeys
5254
});
5355
});
56+
5457
if (!res) {
5558
throw new Error(ALICE_ERROR);
5659
} else if (res.status === 500) {
57-
throw new Error(CONTENT_UNENCRYPTED);
60+
const aliceError = await res.text();
61+
throw new Error(`${CONTENT_UNENCRYPTED} - ${aliceError}`);
5862
} else if (res.status === 409) {
5963
throw new Error(DUPLICATE_MESSAGE);
6064
} else if (res.status !== 200) {

email_mailbox/src/utils/FetchUtils.js

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const PENDING_EVENTS_STATUS_MORE = 201;
77
const NO_EVENTS_STATUS = 204;
88
const EVENTS_BATCH = 25;
99
const NOT_FOUND = 404;
10+
const EXPIRED_SESSION = 401;
1011

1112
export const fetchEmailBody = async ({ bodyKey, optionalToken }) => {
1213
const res = await apiCriptextRequest({
@@ -19,16 +20,16 @@ export const fetchEmailBody = async ({ bodyKey, optionalToken }) => {
1920
const jsonRes = await res.json();
2021
return { status: STATUS_OK, body: jsonRes };
2122
}
22-
case NOT_FOUND: {
23-
throw new Error(signal.CONTENT_NOT_AVAILABLE);
24-
}
25-
default: {
23+
case EXPIRED_SESSION: {
2624
return await checkExpiredSession({
2725
response: { status: res.status },
2826
initialRequest: fetchEmailBody,
2927
requestParams: { bodyKey, optionalToken }
3028
});
3129
}
30+
default: {
31+
throw new Error(signal.CONTENT_NOT_AVAILABLE);
32+
}
3233
}
3334
};
3435

@@ -38,15 +39,22 @@ export const fetchEventAction = async ({ cmd, action, optionalToken }) => {
3839
method: 'GET',
3940
optionalToken
4041
});
41-
if (res.status === STATUS_OK) {
42-
const jsonRes = await res.json();
43-
return { status: STATUS_OK, body: jsonRes };
42+
switch (res.status) {
43+
case STATUS_OK: {
44+
const jsonRes = await res.json();
45+
return { status: STATUS_OK, body: jsonRes };
46+
}
47+
case EXPIRED_SESSION: {
48+
return await checkExpiredSession({
49+
response: { status: res.status },
50+
initialRequest: fetchEventAction,
51+
requestParams: { cmd, action, optionalToken }
52+
});
53+
}
54+
default: {
55+
return { status: res.status };
56+
}
4457
}
45-
return await checkExpiredSession({
46-
response: { status: res.status },
47-
initialRequest: fetchEventAction,
48-
requestParams: { cmd, action, optionalToken }
49-
});
5058
};
5159

5260
/* eslint no-empty: ["error", { "allowEmptyCatch": true }] */
@@ -86,13 +94,16 @@ export const fetchEvents = async optionalToken => {
8694
}
8795
case NO_EVENTS_STATUS:
8896
return { status: STATUS_OK, body: { events: [] } };
89-
default: {
97+
case EXPIRED_SESSION: {
9098
return await checkExpiredSession({
9199
response: { status: res.status },
92100
initialRequest: fetchEvents,
93101
requestParams: optionalToken
94102
});
95103
}
104+
default: {
105+
return { status: res.status };
106+
}
96107
}
97108
};
98109

@@ -103,14 +114,21 @@ export const fetchAcknowledgeEvents = async ({ eventIds, optionalToken }) => {
103114
params: { ids: eventIds },
104115
optionalToken
105116
});
106-
if (res.status === STATUS_OK) {
107-
return { status: STATUS_OK };
117+
switch (res.status) {
118+
case STATUS_OK: {
119+
return { status: STATUS_OK };
120+
}
121+
case EXPIRED_SESSION: {
122+
return await checkExpiredSession({
123+
response: { status: res.status },
124+
initialRequest: fetchAcknowledgeEvents,
125+
requestParams: { eventIds, optionalToken }
126+
});
127+
}
128+
default: {
129+
return { status: res.status };
130+
}
108131
}
109-
return await checkExpiredSession({
110-
response: { status: res.status },
111-
initialRequest: fetchAcknowledgeEvents,
112-
requestParams: { eventIds, optionalToken }
113-
});
114132
};
115133

116134
export const fetchGetSingleEvent = async ({ rowId, optionalToken }) => {
@@ -132,12 +150,15 @@ export const fetchGetSingleEvent = async ({ rowId, optionalToken }) => {
132150
case NO_EVENTS_STATUS:
133151
case NOT_FOUND:
134152
return { status: res.status };
135-
default: {
153+
case EXPIRED_SESSION: {
136154
return await checkExpiredSession({
137155
response: { status: res.status },
138156
initialRequest: fetchGetSingleEvent,
139157
requestParams: { rowId, optionalToken }
140158
});
141159
}
160+
default: {
161+
return { status: res.status };
162+
}
142163
}
143164
};

email_mailbox/src/utils/electronEventInterface.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,8 @@ const formEmailIfNotExists = async params => {
596596
} catch (e) {
597597
if (
598598
e.message === signal.ALICE_ERROR ||
599-
e.message === signal.CONTENT_NOT_AVAILABLE
599+
e.message === signal.CONTENT_NOT_AVAILABLE ||
600+
e instanceof TypeError
600601
) {
601602
return {
602603
error: 1

0 commit comments

Comments
 (0)