Skip to content

ApiError errors field is alway [] during a failed save to datastore #1128

@firemuzzy

Description

@firemuzzy

On preforming a duplicate insert the datastore normally returns

{ "error": { "errors": [ { "domain": "global", "reason": "INVALID_ARGUMENT", "message": "entity already exists" } ], "code": 400, "message": "entity already exists" } }

but instead 'errors' in the ApiError are an []
Is this intentional?

From some digging around, the problem is in lib/datastore/request.js
line 813 creates the request

813: ... request(authenticatedReqOpts, function(err, resp, body)

The value of body is already the expected json error message.
On 'line 819' util.parseHttpRespMessage(resp) sets parsedResp with ApiError with [] for errors.
The callback is called and body param with the nicely formatted error is lost.

The 'message' field is filled but it has the stringified error which would require re-parsing
Bad Request - { "error": { "errors": [ { "domain": "global", "reason": "INVALID_ARGUMENT", "message": "entity already exists" } ], "code": 400, "message": "entity already exists" } }

Metadata

Metadata

Labels

api: datastoreIssues related to the Datastore API.core

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions