mirror of
https://github.com/hexolan/panels.git
synced 2026-03-26 12:40:21 +00:00
manifests
This commit is contained in:
@@ -3,6 +3,7 @@ import type { BaseQueryFn } from '@reduxjs/toolkit/query'
|
||||
|
||||
import { setUnauthed } from './auth'
|
||||
import type { RootState } from '../store'
|
||||
import type { QueryError } from '../types/api';
|
||||
|
||||
const baseQuery = fetchBaseQuery({
|
||||
baseUrl: import.meta.env.VITE_API_URL,
|
||||
@@ -18,7 +19,8 @@ const baseQuery = fetchBaseQuery({
|
||||
}
|
||||
})
|
||||
|
||||
const wrappedBaseQuery: BaseQueryFn = async (args, api, extraOptions) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const wrappedBaseQuery: BaseQueryFn<any, unknown, QueryError> = async (args, api, extraOptions) => {
|
||||
const result = await baseQuery(args, api, extraOptions)
|
||||
if ((api.getState() as RootState).auth.accessToken && result?.error?.status === 403) {
|
||||
api.dispatch(setUnauthed())
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
import type { FetchBaseQueryError } from '@reduxjs/toolkit/query'
|
||||
|
||||
export type QueryError = FetchBaseQueryError | {
|
||||
data: ErrorResponse;
|
||||
}
|
||||
|
||||
export type RawResponse = {
|
||||
status: string;
|
||||
msg?: string;
|
||||
|
||||
@@ -6,7 +6,7 @@ import LoadingBar from '../components/LoadingBar'
|
||||
import { useAppSelector } from '../app/hooks'
|
||||
import { useGetPanelByNameQuery } from '../app/api/panels'
|
||||
import type { Panel } from '../app/types/common'
|
||||
import type { ErrorResponse } from '../app/types/api'
|
||||
import type { QueryError, ErrorResponse } from '../app/types/api'
|
||||
|
||||
export type PanelContext = {
|
||||
panel: Panel;
|
||||
@@ -63,8 +63,8 @@ function PanelLayout() {
|
||||
} else if (!data) {
|
||||
if (!error) {
|
||||
throw Error('Unknown error occured')
|
||||
} else if ('data' in error) {
|
||||
const errResponse = error.data as ErrorResponse
|
||||
} else if ((error as QueryError).data) {
|
||||
const errResponse = (error as QueryError).data as ErrorResponse
|
||||
if (errResponse.msg) {
|
||||
throw Error(errResponse.msg)
|
||||
} else {
|
||||
|
||||
@@ -7,7 +7,7 @@ import LoadingBar from './LoadingBar'
|
||||
import { User } from '../app/types/common'
|
||||
import { useAppSelector } from '../app/hooks'
|
||||
import { useGetUserByNameQuery } from '../app/api/users'
|
||||
import type { ErrorResponse } from '../app/types/api'
|
||||
import type { ErrorResponse, QueryError } from '../app/types/api'
|
||||
|
||||
export type UserContext = {
|
||||
user: User
|
||||
@@ -40,8 +40,8 @@ function UserLayout() {
|
||||
} else if (!data) {
|
||||
if (!error) {
|
||||
throw Error('Unknown error occured')
|
||||
} else if ('data' in error) {
|
||||
const errResponse = error.data as ErrorResponse
|
||||
} else if ((error as QueryError).data) {
|
||||
const errResponse = (error as QueryError).data as ErrorResponse
|
||||
if (errResponse.msg) {
|
||||
throw Error(errResponse.msg)
|
||||
} else {
|
||||
|
||||
@@ -10,7 +10,7 @@ import LoadingBar from '../components/LoadingBar'
|
||||
import { useAppSelector } from '../app/hooks'
|
||||
import { useGetPanelPostQuery } from '../app/api/posts'
|
||||
import type { PanelContext } from '../components/PanelLayout'
|
||||
import type { ErrorResponse } from '../app/types/api'
|
||||
import type { QueryError, ErrorResponse } from '../app/types/api'
|
||||
import type { Comment } from '../app/types/common'
|
||||
|
||||
type PanelPostPageParams = {
|
||||
@@ -37,8 +37,8 @@ function PanelPostPage() {
|
||||
} else if (!data) {
|
||||
if (!error) {
|
||||
throw Error('Unknown error occured')
|
||||
} else if ('data' in error) {
|
||||
const errResponse = error.data as ErrorResponse
|
||||
} else if ((error as QueryError).data) {
|
||||
const errResponse = (error as QueryError).data as ErrorResponse
|
||||
if (errResponse.msg) {
|
||||
throw Error(errResponse.msg)
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user