Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Small Technology Foundation web site
spikes
patronage
Commits
d5dab7d4
Verified
Commit
d5dab7d4
authored
Aug 04, 2019
by
Aral Balkan
Browse files
Add basic error handling
parent
6fbf7d52
Changes
2
Hide whitespace changes
Inline
Side-by-side
.dynamic/client/patron.js
View file @
d5dab7d4
...
...
@@ -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
(
'
E
rror
'
,
error
,
'
error
'
)
Modal
.
fire
(
'
Server e
rror
'
,
error
,
'
error
'
)
return
}
...
...
@@ -75,7 +86,13 @@ window.addEventListener('load', _ => {
}
//
// Interface
// Connectivity.
//
//
// Interface.
//
async
function
confirmCancellation
()
{
...
...
.dynamic/wss/patron.js
View file @
d5dab7d4
...
...
@@ -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
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment