Improve error handling for failure to load boards.json.
This commit is contained in:
parent
9fdc7b6acf
commit
bd76fe89a7
@ -3,24 +3,30 @@ BoardConfig =
|
|||||||
|
|
||||||
init: ->
|
init: ->
|
||||||
if (Conf['boardConfig'].lastChecked or 0) < Date.now() - 2 * $.HOUR
|
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
|
else
|
||||||
@set Conf['boardConfig'].boards
|
@set Conf['boardConfig'].boards
|
||||||
|
|
||||||
load: ->
|
load: ->
|
||||||
if @status is 200
|
if @status is 200 and @response and @response.boards
|
||||||
boards = {}
|
boards = {}
|
||||||
for board in @response.boards
|
for board in @response.boards
|
||||||
boards[board.board] = board
|
boards[board.board] = board
|
||||||
$.set 'boardConfig', {boards, lastChecked: Date.now()}
|
$.set 'boardConfig', {boards, lastChecked: Date.now()}
|
||||||
else
|
else
|
||||||
{boards} = Conf['boardConfig']
|
{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
|
BoardConfig.set boards
|
||||||
|
|
||||||
set: (@boards) ->
|
set: (@boards) ->
|
||||||
for ID, board of @boards
|
for ID, board of g.boards
|
||||||
g.boards[ID]?.config = board
|
board.config = @boards[ID] or {}
|
||||||
for cb in @cbs
|
for cb in @cbs
|
||||||
$.queueTask cb
|
$.queueTask cb
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user