From 8f170078e81dd3268dc1fa1c5aeb9096d4a743ff Mon Sep 17 00:00:00 2001 From: Slava Olishevko Date: Mon, 30 Dec 2024 13:00:22 +0300 Subject: [PATCH] auth: fix unauthorized message issue; feat: delete content-type header; fix: fix pager bug; style: improve right panel style; --- sources/services/ajaxActions.js | 14 ++++++++------ sources/services/auth.js | 26 ++++++++++++++++++++++++-- sources/services/gallery/gallery.js | 4 ++++ sources/styles/pages.less | 1 - 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/sources/services/ajaxActions.js b/sources/services/ajaxActions.js index 081ce33..12b8cbd 100644 --- a/sources/services/ajaxActions.js +++ b/sources/services/ajaxActions.js @@ -66,7 +66,6 @@ class AjaxActions { async _ajaxGet(url, params) { const headers = await getAuthHeaders(); - headers["Content-Type"] = "application/json"; if (!params) { params = {}; } @@ -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() { diff --git a/sources/services/auth.js b/sources/services/auth.js index e1da70c..74d2482 100644 --- a/sources/services/auth.js +++ b/sources/services/auth.js @@ -1,4 +1,5 @@ import IsicClient from "@isic/client"; +import {AxiosError} from "axios"; import constants from "../constants"; import appliedFilters from "../models/appliedFilters"; @@ -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) => { @@ -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) => { @@ -116,6 +120,9 @@ class OAuthISIC { }); } return userInfo; + }) + .catch((e) => { + this.errorHandler(e); }); } @@ -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(); diff --git a/sources/services/gallery/gallery.js b/sources/services/gallery/gallery.js index 369d690..9a4263a 100644 --- a/sources/services/gallery/gallery.js +++ b/sources/services/gallery/gallery.js @@ -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(); } diff --git a/sources/styles/pages.less b/sources/styles/pages.less index 16621e7..55cc418 100644 --- a/sources/styles/pages.less +++ b/sources/styles/pages.less @@ -2073,7 +2073,6 @@ width: 95px; margin-top: -30px; margin-left: 12px; - overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }