feat: error message when resume() did not find data

This commit is contained in:
Ayo 2023-07-16 21:32:03 +02:00
parent 0c9d64c28c
commit 7b72595909

View file

@ -1,3 +1,14 @@
export function resume<T = any>(id: string): T {
return JSON.parse(document.querySelector<HTMLTextAreaElement>(`#${id}`)?.value ?? '')
const element = document.querySelector<HTMLTextAreaElement>(`#${id}`);
if (element?.value)
return JSON.parse(element.value)
throw Error(`The call resume('${id}') did not find any data.
Check that the following are correct:
- The Resumable component is used with correct props
- "data" prop is not undefined
- "${id}" is the "id" of the Resumable component
See examples: https://sr.ht/~ayoayco/astro-resume/#usage
Stack trace: `)
}