Skip to content

Commit

Permalink
auth: fix unauthorized message issue;
Browse files Browse the repository at this point in the history
feat: delete content-type header;
fix: fix pager bug;
style: improve right panel style;
  • Loading branch information
volishevko committed Dec 30, 2024
1 parent c81d6ba commit 8f17007
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
14 changes: 8 additions & 6 deletions sources/services/ajaxActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class AjaxActions {

async _ajaxGet(url, params) {
const headers = await getAuthHeaders();
headers["Content-Type"] = "application/json";
if (!params) {
params = {};
}
Expand All @@ -85,11 +84,14 @@ class AjaxActions {
url: `${API_URL}users/me/`,
headers
};
return axios(axiosConfig)
.then(result => result?.data || {}, (e) => {
webix.message({type: "error", text: e.response.data.detail});
return Promise.reject(e);
});
try {
const userInfoResponse = await axios(axiosConfig);
return userInfoResponse?.data || {};
}
catch (e) {
webix.message({type: "error", text: e.response.data.detail});
throw new Error(e.message, {cause: e});
}
}

async putUserTermsOfUse() {
Expand Down
26 changes: 24 additions & 2 deletions sources/services/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import IsicClient from "@isic/client";
import {AxiosError} from "axios";

import constants from "../constants";
import appliedFilters from "../models/appliedFilters";
Expand Down Expand Up @@ -40,8 +41,8 @@ class OAuthISIC {
state.app.callEvent("login");
}
})
.catch(() => {
logger.error("Authentication: Something went wrong");
.catch((e) => {
this.errorHandler(e);
});
}
webix.attachEvent("onRotate", (landscape) => {
Expand Down Expand Up @@ -94,6 +95,9 @@ class OAuthISIC {
if (userInfo && userInfo.accepted_terms) {
webix.storage.local.put("user", user);
}
})
.catch((e) => {
this.errorHandler(e);
});
}
return new Promise((resolve) => {
Expand All @@ -116,6 +120,9 @@ class OAuthISIC {
});
}
return userInfo;
})
.catch((e) => {
this.errorHandler(e);
});
}

Expand Down Expand Up @@ -186,6 +193,21 @@ class OAuthISIC {
get isLoginRestored() {
return this.#isLoginRestored;
}

errorHandler(e) {
logger.error(e);
if (e.cause instanceof AxiosError) {
if (e.cause.response.status === 401) {
this.login();
}
else {
logger.error("Authentication: bad response");
}
}
else {
logger.error("Authentication: Something went wrong");
}
}
}

const instance = new OAuthISIC();
Expand Down
4 changes: 4 additions & 0 deletions sources/services/gallery/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,10 @@ class GalleryService {
_updatePagerCount(count) {
count = count || 1;
if (count) {
// TODO: fix setPage
if (!this._pager?.$master?.setPage) {
this._pager.$master.setPage = () => {};
}
this._pager.define("count", count);
this._pager.refresh();
}
Expand Down
1 change: 0 additions & 1 deletion sources/styles/pages.less
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,6 @@
width: 95px;
margin-top: -30px;
margin-left: 12px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
Expand Down

0 comments on commit 8f17007

Please sign in to comment.