Add in guards on bad data from web API
This commit is contained in:
@@ -35,6 +35,10 @@ module.exports = PersistenceManager =
|
||||
body = JSON.parse body
|
||||
catch e
|
||||
return callback(e)
|
||||
if !body.lines?
|
||||
return callback(new Error("web API response had no doc lines"))
|
||||
if !body.version? or not body.version instanceof Number
|
||||
return callback(new Error("web API response had no valid doc version"))
|
||||
return callback null, body.lines, body.version
|
||||
else if res.statusCode == 404
|
||||
return callback(new Errors.NotFoundError("doc not not found: #{url}"))
|
||||
|
||||
@@ -84,5 +84,21 @@ describe "PersistenceManager.getDoc", ->
|
||||
|
||||
it "should time the execution", ->
|
||||
@Metrics.Timer::done.called.should.equal true
|
||||
|
||||
|
||||
describe "when request returns an doc without lines", ->
|
||||
beforeEach ->
|
||||
@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(version: @version))
|
||||
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
||||
|
||||
it "should return and error", ->
|
||||
@callback.calledWith(new Error("web API response had no doc lines")).should.equal true
|
||||
|
||||
describe "when request returns an doc without a version", ->
|
||||
beforeEach ->
|
||||
@request.callsArgWith(1, null, {statusCode: 200}, JSON.stringify(lines: @lines))
|
||||
@PersistenceManager.getDoc(@project_id, @doc_id, @callback)
|
||||
|
||||
it "should return and error", ->
|
||||
@callback.calledWith(new Error("web API response had no valid doc version")).should.equal true
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user