forked from Archives/Athou_commafeed
keep more eslint rules enabled
This commit is contained in:
@@ -35,15 +35,10 @@ module.exports = {
|
|||||||
plugins: ["react"],
|
plugins: ["react"],
|
||||||
rules: {
|
rules: {
|
||||||
"@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "as" }],
|
"@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "as" }],
|
||||||
"@typescript-eslint/explicit-function-return-type": "off",
|
|
||||||
"@typescript-eslint/no-confusing-void-expression": ["error", { ignoreArrowShorthand: true }],
|
"@typescript-eslint/no-confusing-void-expression": ["error", { ignoreArrowShorthand: true }],
|
||||||
"@typescript-eslint/no-floating-promises": "off",
|
"@typescript-eslint/no-floating-promises": "off",
|
||||||
"@typescript-eslint/no-misused-promises": "off",
|
"@typescript-eslint/no-misused-promises": "off",
|
||||||
"@typescript-eslint/no-unsafe-assignment": "off",
|
|
||||||
"@typescript-eslint/no-unsafe-member-access": "off",
|
|
||||||
"@typescript-eslint/prefer-nullish-coalescing": ["error", { ignoreConditionalTests: true }],
|
"@typescript-eslint/prefer-nullish-coalescing": ["error", { ignoreConditionalTests: true }],
|
||||||
"@typescript-eslint/strict-boolean-expressions": "off",
|
|
||||||
"@typescript-eslint/unbound-method": "off",
|
|
||||||
"react/no-unescaped-entities": "off",
|
"react/no-unescaped-entities": "off",
|
||||||
"react/react-in-jsx-scope": "off",
|
"react/react-in-jsx-scope": "off",
|
||||||
"react-hooks/exhaustive-deps": "error",
|
"react-hooks/exhaustive-deps": "error",
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import axios from "axios"
|
import axios, { AxiosError } from "axios"
|
||||||
import {
|
import {
|
||||||
type AddCategoryRequest,
|
type AddCategoryRequest,
|
||||||
type AdminSaveUserRequest,
|
type AdminSaveUserRequest,
|
||||||
|
AuthenticationError,
|
||||||
type Category,
|
type Category,
|
||||||
type CategoryModificationRequest,
|
type CategoryModificationRequest,
|
||||||
type CollapseRequest,
|
type CollapseRequest,
|
||||||
@@ -31,19 +32,18 @@ const axiosInstance = axios.create({ baseURL: "./rest", withCredentials: true })
|
|||||||
axiosInstance.interceptors.response.use(
|
axiosInstance.interceptors.response.use(
|
||||||
response => response,
|
response => response,
|
||||||
error => {
|
error => {
|
||||||
if (axios.isAxiosError(error) && error.response) {
|
if (isAuthenticationError(error)) {
|
||||||
const { status, data } = error.response
|
const data = error.response?.data
|
||||||
if (
|
window.location.hash = data?.allowRegistrations ? "/welcome" : "/login"
|
||||||
(status === 401 && data?.message === "Credentials are required to access this resource.") ||
|
|
||||||
(status === 403 && data?.message === "You don't have the required role to access this resource.")
|
|
||||||
) {
|
|
||||||
window.location.hash = data?.allowRegistrations ? "/welcome" : "/login"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw error
|
throw error
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
function isAuthenticationError(error: unknown): error is AxiosError<AuthenticationError> {
|
||||||
|
return axios.isAxiosError(error) && !!error.response && [401, 403].includes(error.response.status)
|
||||||
|
}
|
||||||
|
|
||||||
export const client = {
|
export const client = {
|
||||||
category: {
|
category: {
|
||||||
getRoot: async () => await axiosInstance.get<Category>("category/get"),
|
getRoot: async () => await axiosInstance.get<Category>("category/get"),
|
||||||
@@ -110,11 +110,18 @@ export const errorToStrings = (err: unknown) => {
|
|||||||
let strings: string[] = []
|
let strings: string[] = []
|
||||||
|
|
||||||
if (axios.isAxiosError(err) && err.response) {
|
if (axios.isAxiosError(err) && err.response) {
|
||||||
const { data } = err.response
|
if (typeof err.response.data === "string") strings.push(err.response.data)
|
||||||
if (typeof data === "string") strings.push(data)
|
if (isMessageError(err)) strings.push(err.response.data.message)
|
||||||
if (typeof data === "object" && data.message) strings.push(data.message as string)
|
if (isMessageArrayError(err)) strings = [...strings, ...err.response.data.errors]
|
||||||
if (typeof data === "object" && data.errors) strings = [...strings, ...data.errors]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return strings
|
return strings
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isMessageError(err: AxiosError): err is AxiosError<{ message: string }> {
|
||||||
|
return !!err.response && !!err.response.data && typeof err.response.data === "object" && "message" in err.response.data
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMessageArrayError(err: AxiosError): err is AxiosError<{ errors: string[] }> {
|
||||||
|
return !!err.response && !!err.response.data && typeof err.response.data === "object" && "errors" in err.response.data
|
||||||
|
}
|
||||||
|
|||||||
@@ -284,6 +284,11 @@ export interface AdminSaveUserRequest {
|
|||||||
admin: boolean
|
admin: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AuthenticationError {
|
||||||
|
message: string
|
||||||
|
allowRegistrations: boolean
|
||||||
|
}
|
||||||
|
|
||||||
export type ReadingMode = "all" | "unread"
|
export type ReadingMode = "all" | "unread"
|
||||||
|
|
||||||
export type ReadingOrder = "asc" | "desc"
|
export type ReadingOrder = "asc" | "desc"
|
||||||
|
|||||||
Reference in New Issue
Block a user