manifests

This commit is contained in:
2023-09-27 22:27:52 +01:00
parent 8870c1f7b8
commit e9a1653c4e
17 changed files with 683 additions and 10 deletions

View File

@@ -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())

View File

@@ -1,3 +1,9 @@
import type { FetchBaseQueryError } from '@reduxjs/toolkit/query'
export type QueryError = FetchBaseQueryError | {
data: ErrorResponse;
}
export type RawResponse = {
status: string;
msg?: string;

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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 {