Commit d5dab7d4 authored by Aral Balkan's avatar Aral Balkan

Add basic error handling

parent 6fbf7d52
......@@ -3,18 +3,29 @@ window.addEventListener('load', _ => {
$ = document.querySelector.bind(document)
const Modal = Swal
const socket = new WebSocket(`wss://${window.location.hostname}/patron`)
// Display the state of the connection.
socket.onopen = _ => { $('#status').innerHTML = '<span style="color: green">Online</span>' }
socket.onclose = _ => { $('#status').innerHTML = 'Offline' }
// Handle connectivity.
socket.onopen = _ => {
$('#status').innerHTML = '<span style="color: green">Online</span>'
}
socket.onclose = _ => {
$('#status').innerHTML = 'Offline'
}
socket.onerror = error => {
Modal.fire('Connection error', error, 'error')
}
// Display received messages.
socket.onmessage = message => {
response = JSON.parse(message.data)
if (response.error) {
Modal.fire('Error', error, 'error')
Modal.fire('Server error', error, 'error')
return
}
......@@ -75,7 +86,13 @@ window.addEventListener('load', _ => {
}
//
// Interface
// Connectivity.
//
//
// Interface.
//
async function confirmCancellation () {
......
......@@ -34,11 +34,16 @@ module.exports = (webSocket, request) => {
const command = JSON.parse(data)
console.log(` 🤗 Patronage: ${command.action} ${command.itemId} ${command.action === 'update' ? `(to €${command.amount}/month)` : ''}`)
let result
switch (command.action) {
case 'update':
// Update the patronage amount, starting with the next payment (not prorated).
try {
result = await stripe.subscriptions.update(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment