Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix: minor errors with fetch request

thecodrr5c519f17e661
diff --git a/packages/core/api/index.js b/packages/core/api/index.js
index c73d53401..a8cf10c62 100644
--- a/packages/core/api/index.js
+++ b/packages/core/api/index.js
@@ -92,7 +92,7 @@ class Database {
}
if (!user || !user.accessToken) {
- user = await this.user.get();
+ user = await this.user.getUser();
}
if (!user) return;
diff --git a/packages/core/api/sync/index.js b/packages/core/api/sync/index.js
index bd023b288..0976013cc 100644
--- a/packages/core/api/sync/index.js
+++ b/packages/core/api/sync/index.js
@@ -49,7 +49,7 @@ export default class Sync {
async _fetch(lastSynced, token) {
return await http.get(
- `${Constants.AUTH_HOST}/sync?lst=${lastSynced}`,
+ `${Constants.API_HOST}/sync?lst=${lastSynced}`,
token
);
}
diff --git a/packages/core/utils/http.js b/packages/core/utils/http.js
index 0e2f8b629..6d0a02d3c 100644
--- a/packages/core/utils/http.js
+++ b/packages/core/utils/http.js
@@ -37,7 +37,6 @@ async function handleResponse(response) {
if (response.ok) {
return json;
}
-
let error = json.error || json.errors.join("\n");
throw new Error(error);
} else {
@@ -53,7 +52,7 @@ async function request(url, token, method) {
return handleResponse(
await fetch(url, {
method,
- headers: { Authorization: token ? "Bearer " + token : undefined },
+ headers: getAuthorizationHeader(token),
})
);
}
@@ -64,7 +63,7 @@ async function bodyRequest(url, data, json = true, token, method) {
method,
body: transformer(data, json),
headers: {
- Authorization: token ? "Bearer " + token : undefined,
+ ...getAuthorizationHeader(token),
"Content-Type": json
? "application/json"
: "application/x-www-form-urlencoded",
@@ -73,6 +72,10 @@ async function bodyRequest(url, data, json = true, token, method) {
);
}
+function getAuthorizationHeader(token) {
+ return token ? { Authorization: "Bearer " + token } : {};
+}
+
export default {
get,
post,