Skip to content

Instantly share code, notes, and snippets.

@codebryo
Created June 3, 2016 08:52
Show Gist options
  • Save codebryo/c9bef90ee82d233f1c21a9434350ef24 to your computer and use it in GitHub Desktop.
Save codebryo/c9bef90ee82d233f1c21a9434350ef24 to your computer and use it in GitHub Desktop.
Me trying to understand what's going on with error rendering, fetching and so on in a Angular based project
# As I understand it
# 1. When Build is Finished - GET ERRORS FROM THE SERVER
# 2. Collect Errors for the whole build
# 3. Show those Errors
# 4. Allow to click on any error to make it disappear
# WHAT I FOUND SPLITTED INTO 2 FILES
# GLOBAL Variables
@allErrors = {}
@_errorListeners = []
# ON INITIATING
@build.addErrorListener(@addErrors.bind(this))
# -> add errors is a anonymous function that takes errors. We bind (this) to it
@addErrors = (errors) =>
errors = errors.filter( (item) =>
!@allErrors[item.type + item.msg]
)
errors.forEach( (item) =>
@allErrors[item.type + item.msg] = true
)
@buildErrors = @buildErrors.concat(errors)
# ERROR LISTENERS ?
# The listener is the anonymous addErrros function
addErrorListener: (listener) ->
@_errorListeners.push(listener) unless listener in @_errorListeners
# OKAY... now the ui is running somehow... we'll update the build status and process that
_processStatusResponse: (response) =>
@setStatus(response.data.type)
if @isFinished()
@_fetchErrorList(@addErrors) # okay, if it's finishes. Call the fetch Errors function
else
setTimeout(@_fetchStatus, POLLING_INTERVAL)
# ->
_fetchErrorList: =>
JetBuild.fetch.getData("#{@id()}/errors")
.then(@_processErrorListResponse)
.catch( =>
setTimeout(@_fetchErrorList, POLLING_INTERVAL)
)
# ->
_processErrorListResponse: (response) =>
@dispatchErrors response.data.build_errors # why not put this in the above line ?
# ->
dispatchErrors: (errors) ->
listener(errors) for listener in @_errorListeners
# Okay, then in the UI the errors get rendered at some point.
# They also have that click event bound to it
@onRemoveErrorMessage = (index) ->
@buildErrors.splice(index, 1)[0]
return
# THIS IS NEVER USED ..... WHYYYYYYYY
_addSystemError = (data, status) =>
unless status == 404
@addErrors [{
type: "BUILD_ERROR_TYPE_SYSTEM",
msg: "An error occurred on our server. Status: #{status}"
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment