 check_status_success = (dom) ->
   status = dom.getElementsByTagNameNS(XMLNS.SAMLP, 'Status')
   return false unless status.length is 1
-  for status_code in status[0].childNodes
+  for status_code in status[0].childNodes or []
     if status_code.attributes?
-      for attr in status_code.attributes
-        return true if attr.name is 'Value' and attr.value is 'urn:oasis:names:tc:SAML:2.0:status:Success'
+      for attr in status_code.attributes or []
+        return true if attr?.name is 'Value' and attr?.value is 'urn:oasis:names:tc:SAML:2.0:status:Success'
   false
 
 get_status = (dom) ->

  throw new Error("Expected 1 Response; found #{response.length}") unless response.length is 1

  response_header = {}
  for attr in response[0].attributes
    switch attr.name
      when "Version"
        throw new Error "Invalid SAML Version #{attr.value}" unless attr.value is "2.0"
      when "Destination"

  status = dom.getElementsByTagNameNS(XMLNS.SAMLP, 'Status')
  return status_list unless status.length is 1

  for status_code in status[0].childNodes or []
    if status_code.attributes?
      for attr in status_code?.attributes or []
        if attr?.name is 'Value'
          top_status = attr.value
          status_list[top_status] ?= []
    for sub_status_code in status_code.childNodes or []
      if sub_status_code?.attributes?
        for attr in sub_status_code.attributes or []
          if attr?.name is 'Value'
            status_list[top_status].push attr?.value
  status_list

to_error = (err) ->
