         callback(text)
         callback()
       protocol.interceptStringProtocol 'http', doubleHandler, (error) ->
+        return done(error) if error
         $.ajax
           url: 'http://fake-host'
           success: (data) ->

    it 'can intercept http protocol', (done) ->
      handler = (request, callback) -> callback(new Buffer(text))
      protocol.interceptBufferProtocol 'http', handler, (error) ->
        $.ajax
          url: 'http://fake-host'
          success: (data) ->

    it 'sends object as response', (done) ->
      handler = (request, callback) -> callback(data: buffer, mimeType: 'text/html')
      protocol.registerBufferProtocol protocolName, handler, (error) ->
        return done(error) if error
        $.ajax
          url: "#{protocolName}://fake-host"
          success: (data, statux, request) ->
