Improve error handling for failure to load boards.json.

This commit is contained in:
ccd0 2016-07-10 03:09:08 -07:00
parent 9fdc7b6acf
commit bd76fe89a7

View File

@ -3,24 +3,30 @@ BoardConfig =
init: ->
if (Conf['boardConfig'].lastChecked or 0) < Date.now() - 2 * $.HOUR
$.ajax '//a.4cdn.org/boards.json', onloadend: @load
$.ajax '//a.4cdn.org/boards.json',
onloadend: @load
timeout: 5 * $.SECOND
else
@set Conf['boardConfig'].boards
load: ->
if @status is 200
if @status is 200 and @response and @response.boards
boards = {}
for board in @response.boards
boards[board.board] = board
$.set 'boardConfig', {boards, lastChecked: Date.now()}
else
{boards} = Conf['boardConfig']
new Notice 'warning', "Failed to load board configuration data. Error #{@statusText} (#{@status})", 20
err = switch @status
when 0 then 'Connection Error'
when 200 then 'Invalid Data'
else "Error #{@statusText} (#{@status})"
new Notice 'warning', "Failed to load board configuration. #{err}", 20
BoardConfig.set boards
set: (@boards) ->
for ID, board of @boards
g.boards[ID]?.config = board
for ID, board of g.boards
board.config = @boards[ID] or {}
for cb in @cbs
$.queueTask cb
return