forked from polka_billy/porridger
Added http errors handing to all fettch requests
This commit is contained in:
@ -9,6 +9,7 @@ import { useAddAnnouncement, useTrashboxes } from "../hooks/api"
|
||||
import { categoryNames } from "../assets/category"
|
||||
import { stations, lines, lineNames } from "../assets/metro"
|
||||
import { isObject } from "../utils/types"
|
||||
import { handleHTTPErrors } from "../utils"
|
||||
|
||||
function AddPage() {
|
||||
const [addressPosition, setAddressPosition] = useState(latLng(59.972, 30.3227))
|
||||
@ -22,6 +23,8 @@ function AddPage() {
|
||||
try {
|
||||
const res = await fetch(location.protocol + "//nominatim.openstreetmap.org/search?format=json&q=" + address)
|
||||
|
||||
handleHTTPErrors(res)
|
||||
|
||||
const fetchData: unknown = await res.json()
|
||||
|
||||
console.log("f", fetchData)
|
||||
@ -37,6 +40,8 @@ function AddPage() {
|
||||
try {
|
||||
const res = await fetch(`${location.protocol}//nominatim.openstreetmap.org/reverse?format=json&accept-language=ru&lat=${addressPosition.lat}&lon=${addressPosition.lng}`)
|
||||
|
||||
handleHTTPErrors(res)
|
||||
|
||||
const fetchData: unknown = await res.json()
|
||||
|
||||
if (!isObject<{ display_name: string }>(fetchData, { "display_name": "string" })) {
|
||||
|
Reference in New Issue
Block a user