Skip to content

Commit eb40820

Browse files
committed
fix: route crashing
1 parent 11c75e0 commit eb40820

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

server/src/models/Route.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,13 @@ class Route extends Model {
115115
const results = await query
116116

117117
return results.map((result) => {
118-
if (typeof result.waypoints === 'string') {
119-
result.waypoints = JSON.parse(result.waypoints)
120-
} else if (result.waypoints === null) {
118+
if (typeof result.waypoints === 'string' && result.waypoints) {
119+
try {
120+
result.waypoints = JSON.parse(result.waypoints)
121+
} catch {
122+
result.waypoints = []
123+
}
124+
} else if (!result.waypoints) {
121125
result.waypoints = []
122126
}
123127
return result
@@ -162,14 +166,22 @@ class Route extends Model {
162166

163167
if (!result) return null
164168

165-
if (typeof result.waypoints === 'string') {
166-
result.waypoints = JSON.parse(result.waypoints)
167-
} else if (result.waypoints === null) {
169+
if (typeof result.waypoints === 'string' && result.waypoints) {
170+
try {
171+
result.waypoints = JSON.parse(result.waypoints)
172+
} catch {
173+
result.waypoints = []
174+
}
175+
} else if (!result.waypoints) {
168176
result.waypoints = []
169177
}
170-
if (typeof result.tags === 'string') {
171-
result.tags = JSON.parse(result.tags)
172-
} else if (result.tags === null) {
178+
if (typeof result.tags === 'string' && result.tags) {
179+
try {
180+
result.tags = JSON.parse(result.tags)
181+
} catch {
182+
result.tags = []
183+
}
184+
} else if (!result.tags) {
173185
result.tags = []
174186
}
175187
if (typeof result.image === 'string') {

0 commit comments

Comments
 (0)