parse-tolerate

This commit is contained in:
Untone 2024-02-17 17:28:57 +03:00
parent 6fa6076f9f
commit 002ffe64fc
3 changed files with 4 additions and 4 deletions

View File

@ -135,7 +135,7 @@ export const FullArticle = (props: Props) => {
const media = createMemo<MediaItem[]>(() => {
try {
return JSON.parse(props.article.media)
return JSON.parse(props.article?.media || "[]")
} catch {
return []
}

View File

@ -50,7 +50,7 @@ export const ConnectProvider = (props: { children: JSX.Element }) => {
Authorization: token,
},
onmessage(event) {
const m: SSEMessage = JSON.parse(event.data)
const m: SSEMessage = JSON.parse(event.data || "{}")
console.log('[context.connect] Received message:', m)
// Iterate over all registered handlers and call them

View File

@ -72,7 +72,7 @@ const saveDraftToLocalStorage = (formToSave: ShoutForm) => {
localStorage.setItem(`shout-${formToSave.shoutId}`, JSON.stringify(formToSave))
}
const getDraftFromLocalStorage = (shoutId: number) => {
return JSON.parse(localStorage.getItem(`shout-${shoutId}`) || '')
return JSON.parse(localStorage.getItem(`shout-${shoutId}`) || '{}')
}
const removeDraftFromLocalStorage = (shoutId: number) => {
@ -105,7 +105,7 @@ export const EditorProvider = (props: { children: JSX.Element }) => {
return false
}
const parsedMedia = JSON.parse(form.media || '')
const parsedMedia = JSON.parse(form.media || '[]')
if (form.layout === 'video' && !parsedMedia[0]) {
snackbar?.showSnackbar({
type: 'error',