mirror of
https://git.sr.ht/~cadence/cloudtube
synced 2026-03-02 02:31:35 +00:00
Improve documentation and errors around local mode
This commit is contained in:
parent
83c34f75d9
commit
539260c8de
4 changed files with 37 additions and 7 deletions
|
|
@ -1,18 +1,44 @@
|
|||
import {q} from "./elemjs/elemjs.js"
|
||||
const q = s => document.querySelector(s) // write this directly rather than importing to avoid an extra round-trip
|
||||
|
||||
const status = q("#status")
|
||||
let status = q("#status")
|
||||
const form = q("#form")
|
||||
const data = q("#video-data")
|
||||
|
||||
function displayError(root) {
|
||||
let contents
|
||||
if (root instanceof Error) { // error in our code here, or fetch API promise rejection
|
||||
contents = root.toString()
|
||||
if (root.stack) contents += root.stack
|
||||
} else { // some JSON something
|
||||
if (root.error) { // a descriptive report from the instance
|
||||
contents = root.error.message || root.error
|
||||
if (root.error.identifier) contents += `\nIdentifier: ${root.error.identifier}`
|
||||
} else {
|
||||
contents = JSON.stringify(root, null, 2)
|
||||
}
|
||||
}
|
||||
|
||||
console.log(contents)
|
||||
|
||||
const newStatus = document.createElement("pre")
|
||||
newStatus.id = "status"
|
||||
newStatus.textContent = contents
|
||||
status.replaceWith(newStatus)
|
||||
status = newStatus
|
||||
}
|
||||
|
||||
fetch(`http://localhost:3000/api/v1/videos/${id}`).then(res => res.json()).then(root => {
|
||||
if (root.error) throw new Error(root)
|
||||
if (root.error) {
|
||||
throw root // it's ok to throw this, it will be caught and displayed
|
||||
}
|
||||
|
||||
data.value = JSON.stringify(root)
|
||||
form.submit()
|
||||
status.textContent = "Submitting..."
|
||||
}).catch(e => {
|
||||
if (e.message.includes("NetworkError")) {
|
||||
if (e.message && e.message.includes("NetworkError")) {
|
||||
status.textContent = "Connection failed. Make sure you're running your own instance locally."
|
||||
} else {
|
||||
status.innerText = e.toString()
|
||||
displayError(e)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue