Add JSON.parse error-handling when parsing from URL
This commit is contained in:
parent
40891cd4ce
commit
fa785a726c
@ -34,7 +34,20 @@ const MultiEdit = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const q = parse(props.location.search);
|
const q = parse(props.location.search);
|
||||||
const data = JSON.parse(q.data as string) // TODO: verify what happens when data is string[]
|
|
||||||
|
let data: object;
|
||||||
|
if (cat === 'like'){
|
||||||
|
data = { like: true }
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
// TODO: verify what happens if data is string[]
|
||||||
|
data = JSON.parse(q.data as string);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error, q)
|
||||||
|
data = {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const title = sectionTitleFromCat(cat);
|
const title = sectionTitleFromCat(cat);
|
||||||
return (
|
return (
|
||||||
<Sidebar>
|
<Sidebar>
|
||||||
|
@ -142,11 +142,17 @@ class MapApp extends React.Component<MapAppProps, MapAppState> {
|
|||||||
colourBuilding(building) {
|
colourBuilding(building) {
|
||||||
const cat = this.props.match.params.category;
|
const cat = this.props.match.params.category;
|
||||||
const q = parse(window.location.search);
|
const q = parse(window.location.search);
|
||||||
const data = (cat === 'like') ? { like: true } : JSON.parse(q.data as string); // TODO: verify what happens if data is string[]
|
|
||||||
if (cat === 'like') {
|
if (cat === 'like') {
|
||||||
this.likeBuilding(building.building_id)
|
this.likeBuilding(building.building_id)
|
||||||
} else {
|
} else {
|
||||||
|
try {
|
||||||
|
// TODO: verify what happens if data is string[]
|
||||||
|
const data = JSON.parse(q.data as string);
|
||||||
this.updateBuilding(building.building_id, data)
|
this.updateBuilding(building.building_id, data)
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error, q)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user