From a661376d1630a22eb0733283fbecad0425ff74da Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Mon, 25 Oct 2021 17:34:39 -0400 Subject: [PATCH] Catch errors when uploading white avatar (#3119) --- js/src/common/models/User.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/js/src/common/models/User.js b/js/src/common/models/User.js index f8d9ebfde..97de0d8d3 100644 --- a/js/src/common/models/User.js +++ b/js/src/common/models/User.js @@ -89,8 +89,18 @@ Object.assign(User.prototype, { const user = this; image.onload = function () { - const colorThief = new ColorThief(); - user.avatarColor = colorThief.getColor(this); + try { + const colorThief = new ColorThief(); + user.avatarColor = colorThief.getColor(this); + } catch (e) { + // Completely white avatars throw errors due to a glitch in color thief + // See https://github.com/lokesh/color-thief/issues/40 + if (e instanceof TypeError) { + user.avatarColor = [255, 255, 255]; + } else { + throw e; + } + } user.freshness = new Date(); m.redraw(); };