mirror of
https://github.com/comatory/fb2iCal
synced 2025-06-05 22:09:25 +02:00
add JSON response for errors when using JS
This commit is contained in:
@@ -1,7 +1,19 @@
|
|||||||
const FBURLError = () => new Error('Not a valid Facebook URL!')
|
const FBURLError = () => new Error('Not a valid Facebook URL!')
|
||||||
|
|
||||||
|
const sendJSON = (req) => {
|
||||||
|
return req.accepts().includes('application/json')
|
||||||
|
}
|
||||||
|
|
||||||
const genericErrorHandler = (err, req, res, next) => {
|
const genericErrorHandler = (err, req, res, next) => {
|
||||||
console.error(err.stack)
|
console.error(err.stack)
|
||||||
|
|
||||||
|
if (sendJSON(req)) {
|
||||||
|
res
|
||||||
|
.status(500)
|
||||||
|
.send({ error: err.toString() })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
res
|
res
|
||||||
.status(500)
|
.status(500)
|
||||||
.render('error', { error: err.toString() })
|
.render('error', { error: err.toString() })
|
||||||
|
@@ -172,7 +172,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleError = (error) => {
|
const handleError = (error) => {
|
||||||
console.error(error)
|
|
||||||
finishedRequest()
|
finishedRequest()
|
||||||
setStatusError(error)
|
setStatusError(error)
|
||||||
}
|
}
|
||||||
@@ -182,11 +181,16 @@
|
|||||||
fetch('/download', {
|
fetch('/download', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
'Accept': 'text/calendar, application/json',
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
},
|
},
|
||||||
body: data,
|
body: data,
|
||||||
}).then((response) => {
|
}).then((response) => {
|
||||||
if (response.status === 500) {
|
if (response.status !== 200) {
|
||||||
|
if (response.body.constructor === ReadableStream) {
|
||||||
|
response.json().then((json) => reject(json.error || response.statusText))
|
||||||
|
return
|
||||||
|
}
|
||||||
reject(response.statusText)
|
reject(response.statusText)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -195,6 +199,7 @@
|
|||||||
}).catch(reject)
|
}).catch(reject)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
window.postURL = postURL
|
||||||
|
|
||||||
const form = document.querySelector('form')
|
const form = document.querySelector('form')
|
||||||
const submitButton = document.querySelector("#submit")
|
const submitButton = document.querySelector("#submit")
|
||||||
|
@@ -23,22 +23,21 @@
|
|||||||
into your calendar.
|
into your calendar.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<div class="row">
|
<form action='/download' method='POST' id="form">
|
||||||
<form action='/download' method='POST' id="form">
|
<input id="url" type='text' name='url' placeholder='Paste / type FB event URL here...' />
|
||||||
<input id="url" type='text' name='url' placeholder='Paste / type FB event URL here...' />
|
<input id="submit" type='submit' value='Submit' />
|
||||||
<input id="submit" type='submit' value='Submit' />
|
</form>
|
||||||
</form>
|
|
||||||
<div id="status">
|
<div id="status">
|
||||||
<div class="status-item" id="network">
|
<div class="status-item" id="network">
|
||||||
Fetching file...
|
Fetching file...
|
||||||
</div>
|
</div>
|
||||||
<div class="status-item" id="parsing">
|
<div class="status-item" id="parsing">
|
||||||
Parsing data...
|
Parsing data...
|
||||||
</div>
|
</div>
|
||||||
<div class="status-item" id="error">
|
<div class="status-item" id="error">
|
||||||
</div>
|
</div>
|
||||||
<div class="status-item" id="service-worker">
|
<div class="status-item" id="service-worker">
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user