handling erorr response and empty reviews
This commit is contained in:
parent
96185ab95a
commit
788610292e
@ -86,7 +86,12 @@ function LocationDetail() {
|
|||||||
setCurrentUserReview(res.data)
|
setCurrentUserReview(res.data)
|
||||||
setPageState({ ...pageState, enable_post: false})
|
setPageState({ ...pageState, enable_post: false})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error)
|
console.log(error)
|
||||||
|
let err = error as IHttpResponse;
|
||||||
|
if(err.status == 404) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
alert(err.error.response.data.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -390,6 +395,8 @@ function LocationDetail() {
|
|||||||
}
|
}
|
||||||
<div name={'CRTICITS REVIEW'} style={{ margin: '50px 0', textAlign: 'left' }}>
|
<div name={'CRTICITS REVIEW'} style={{ margin: '50px 0', textAlign: 'left' }}>
|
||||||
<SeparatorWithAnchor pageName={"critic's review"} pageLink='#' />
|
<SeparatorWithAnchor pageName={"critic's review"} pageLink='#' />
|
||||||
|
{locationDetail.critics_review.length > 0 ?
|
||||||
|
<>
|
||||||
<div className={'criticSortFilter'}>
|
<div className={'criticSortFilter'}>
|
||||||
<div className={'inline-block text-sm'}>Sort by: </div>
|
<div className={'inline-block text-sm'}>Sort by: </div>
|
||||||
<a className={'dropdownLabel'} onClick={() => setPageState({ ...pageState, show_sort: !pageState.show_sort })}>
|
<a className={'dropdownLabel'} onClick={() => setPageState({ ...pageState, show_sort: !pageState.show_sort })}>
|
||||||
@ -451,6 +458,14 @@ function LocationDetail() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
</>
|
||||||
|
|
||||||
|
:
|
||||||
|
<>
|
||||||
|
<span className={'text-sm italic'}>No Critics review to display</span>
|
||||||
|
</>
|
||||||
|
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div name={'USERS REVIEW'} style={{ margin: '50px 0', textAlign: 'left' }}>
|
<div name={'USERS REVIEW'} style={{ margin: '50px 0', textAlign: 'left' }}>
|
||||||
|
@ -2,7 +2,7 @@ import { AxiosError } from "axios";
|
|||||||
import { LOGIN_URI, SIGNUP_URI } from "../constants/api";
|
import { LOGIN_URI, SIGNUP_URI } from "../constants/api";
|
||||||
import { client } from "./config";
|
import { client } from "./config";
|
||||||
|
|
||||||
const initialState: IEmptyResponseState = {
|
const initialState: IHttpResponse = {
|
||||||
data: null,
|
data: null,
|
||||||
error: AxiosError
|
error: AxiosError
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@ import { AxiosError } from "axios"
|
|||||||
import { client } from "./config";
|
import { client } from "./config";
|
||||||
import { GET_CURRENT_USER_REVIEW_LOCATION_URI, POST_REVIEW_LOCATION_URI } from "../constants/api";
|
import { GET_CURRENT_USER_REVIEW_LOCATION_URI, POST_REVIEW_LOCATION_URI } from "../constants/api";
|
||||||
|
|
||||||
const initialState: IEmptyResponseState = {
|
const initialState: IHttpResponse = {
|
||||||
data: null,
|
data: null,
|
||||||
error: AxiosError
|
error: AxiosError,
|
||||||
|
status: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
interface postReviewLocationReq {
|
interface postReviewLocationReq {
|
||||||
@ -29,7 +30,7 @@ async function postReviewLocation(req: postReviewLocationReq) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCurrentUserLocationReviewService(location_id: number) {
|
async function getCurrentUserLocationReviewService(location_id: number): Promise<IHttpResponse> {
|
||||||
const newState = { ...initialState };
|
const newState = { ...initialState };
|
||||||
try {
|
try {
|
||||||
const response = await client({ method: 'GET', url: `${GET_CURRENT_USER_REVIEW_LOCATION_URI}/${location_id}`, withCredentials: true})
|
const response = await client({ method: 'GET', url: `${GET_CURRENT_USER_REVIEW_LOCATION_URI}/${location_id}`, withCredentials: true})
|
||||||
@ -37,7 +38,10 @@ async function getCurrentUserLocationReviewService(location_id: number) {
|
|||||||
newState.error = null
|
newState.error = null
|
||||||
return newState
|
return newState
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
let error = err as AxiosError;
|
||||||
|
newState.error = error
|
||||||
|
newState.status = error.response?.status;
|
||||||
|
throw(newState)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ interface GetRequestPagination {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
interface IEmptyResponseState {
|
interface IHttpResponse {
|
||||||
data: any,
|
data: any,
|
||||||
error: any,
|
error: any,
|
||||||
|
status?: number,
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user