Skip to content

Commit 76dfff4

Browse files
committed
Catch json parse exception in JavaScript
1 parent cc61ab1 commit 76dfff4

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/main/webapp/player.html

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -711,21 +711,28 @@ <h3 class="col text-muted">
711711
handleImageData(data);
712712
}
713713
else {
714-
var notificationEvent = JSON.parse(data);
715-
if(notificationEvent != null && typeof(notificationEvent) == "object")
716-
{
717-
var eventType = notificationEvent.eventType;
718-
if (eventType == "UPDATE_AUDIO_LEVEL") {
719-
//
720-
console.debug("Update audio level from server(max:0, min:127): " + notificationEvent.audioLevel);
714+
var notificationEvent;
715+
try {
716+
notificationEvent = JSON.parse(data);
717+
if(notificationEvent != null && typeof(notificationEvent) == "object")
718+
{
719+
var eventType = notificationEvent.eventType;
720+
if (eventType == "UPDATE_AUDIO_LEVEL") {
721+
//
722+
console.debug("Update audio level from server(max:0, min:127): " + notificationEvent.audioLevel);
723+
}
724+
else {
725+
$("#all-messages").append("Received: " + data + "<br>");
726+
}
721727
}
722728
else {
723729
$("#all-messages").append("Received: " + data + "<br>");
724730
}
725731
}
726-
else {
732+
catch (exception) {
727733
$("#all-messages").append("Received: " + data + "<br>");
728734
}
735+
729736
}
730737
}
731738
else if (info == "bitrateMeasurement") {

0 commit comments

Comments
 (0)