Openstatus www.openstatus.dev

chore(play-checker): validation and console mute (#993)

* chore: mute console

* chore: add validation

* chore: mute console

* ci: apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>

authored by

Maximilian Kaske
autofix-ci[bot]
and committed by
GitHub
ac7a45a5 c5cb867c

+13 -7
+8 -6
apps/web/src/app/play/checker/_components/checker-form.tsx
··· 44 44 type RegionChecker, 45 45 is32CharHex, 46 46 latencyFormatter, 47 + regionCheckerSchema, 47 48 regionFormatter, 48 49 } from "@/components/ping-response-analysis/utils"; 49 50 import useUpdateSearchParams from "@/hooks/use-update-search-params"; ··· 168 169 }); 169 170 } 170 171 } else { 171 - const parsed = JSON.parse(item) as RegionChecker; 172 - return parsed; 172 + const parsed = JSON.parse(item); 173 + const validation = 174 + regionCheckerSchema.safeParse(parsed); 175 + if (!validation.success) return null; 176 + return validation.data; 173 177 } 174 178 return null; 175 - } catch (e) { 176 - console.error(e); 179 + } catch (_e) { 177 180 return null; 178 181 } 179 182 }) ··· 195 198 } 196 199 } 197 200 } 198 - } catch (e) { 199 - console.log(e); 201 + } catch (_e) { 200 202 const searchParams = updateSearchParams({ id: null }); 201 203 router.replace(`${pathname}?${searchParams}`); 202 204 toast.error("Something went wrong", {
+5 -1
apps/web/src/components/ping-response-analysis/utils.ts
··· 115 115 checks: checkerSchema.extend({ region: monitorFlyRegionSchema }).array(), 116 116 }); 117 117 118 + export const regionCheckerSchema = checkerSchema.extend({ 119 + region: monitorFlyRegionSchema, 120 + }); 121 + 118 122 export type Timing = z.infer<typeof timingSchema>; 119 123 export type Checker = z.infer<typeof checkerSchema>; 120 - export type RegionChecker = Checker & { region: MonitorFlyRegion }; 124 + export type RegionChecker = z.infer<typeof regionCheckerSchema>; 121 125 export type Method = "GET" | "POST" | "PUT" | "DELETE" | "HEAD"; 122 126 export type CachedRegionChecker = z.infer<typeof cachedCheckerSchema>; 123 127