Skip to content

Commit

Permalink
chore(app): updating error management
Browse files Browse the repository at this point in the history
  • Loading branch information
razshare committed Apr 7, 2024
1 parent 490e9f4 commit 5cf7dc8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@microsoft/fetch-event-source": "^2.0.1",
"@sveltejs/kit": "^1.25.2 || ^2.0.0",
"svelte": "^4.0.0",
"svelte-unsafe": "^0.1.0"
"svelte-unsafe": "^0.2.0"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.0.0",
Expand All @@ -50,7 +50,7 @@
"publint": "^0.1.9",
"svelte": "^4.2.7",
"svelte-check": "^3.6.0",
"svelte-unsafe": "^0.1.0",
"svelte-unsafe": "^0.2.0",
"tslib": "^2.4.1",
"typescript": "^5.0.0",
"vite": "^5.0.11"
Expand Down
50 changes: 25 additions & 25 deletions src/lib/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ function create({ id, data }) {
})
}
destroying = true
const destroyAttempt = await _interface.delete(id)
if (destroyAttempt.error) {
return destroyAttempt
const [, destroyError] = await _interface.delete(id)
if (destroyError) {
return error(destroyError)
}
destroyed = true
const callbacks = events.get('destroy') ?? []
Expand Down Expand Up @@ -247,11 +247,11 @@ export const session = {
let exists = true
do {
id = uuid()
const existsAttempt = await _interface.exists(id)
if (existsAttempt.error) {
return error(existsAttempt.error)
const [existsValue, existsError] = await _interface.exists(id)
if (existsError) {
return error(existsError)
}
exists = existsAttempt.value
exists = existsValue
} while (exists)
}

Expand All @@ -260,23 +260,23 @@ export const session = {
*/
let sessionLocal

const hasAttempt = await _interface.has(id)
const [hasValue, hasError] = await _interface.has(id)

if (hasAttempt.error) {
return error(hasAttempt.error)
if (hasError) {
return error(hasError)
}

if (hasAttempt.value) {
const getAttempt = await _interface.get(id)
if (getAttempt.error) {
return error(getAttempt.error)
if (hasValue) {
const [getValue, getError] = await _interface.get(id)
if (getError) {
return error(getError)
}
sessionLocal = getAttempt.value
sessionLocal = getValue
} else {
sessionLocal = create({ id, data: new Map() })
const setAttempt = await _interface.set(id, sessionLocal)
if (setAttempt.error) {
return error(setAttempt.error)
const [, setError] = await _interface.set(id, sessionLocal)
if (setError) {
return error(setError)
}
}

Expand All @@ -296,19 +296,19 @@ export const session = {
* @returns {Promise<import('svelte-unsafe').Unsafe<void>>} Error if no session with the given `id` is found, otherwise success.
*/
async destroy({ id }) {
const getAttempt = await _interface.get(id)
if (getAttempt.error) {
return error(getAttempt.error)
const [getValue, getError] = await _interface.get(id)
if (getError) {
return error(getError)
}
const session = getAttempt.value
const session = getValue

if (!session) {
return error(`Session ${id} not found.`)
}

const deleteAttempt = await _interface.delete(id)
if (deleteAttempt.error) {
return error(deleteAttempt.error)
const [, deleteError] = await _interface.delete(id)
if (deleteError) {
return error(deleteError)
}

return ok()
Expand Down

0 comments on commit 5cf7dc8

Please sign in to comment.