jpillora / node-edit-google-spreadsheet

A simple API for editing Google Spreadsheets
304 stars 101 forks source link

Spreadsheet.prototype.send should check response.statusCode #21

Closed mxmz closed 10 years ago

mxmz commented 10 years ago

If response.statusCode != 200 and body doesn't include "success='0'" (which, for example, occurs if your token has expired), no error is reported.

jpillora commented 10 years ago

Hmm is there a more precise way to parse the errors? I just used success='0' as a hack until I discovered the "real" way

mxmz commented 10 years ago

Do we really need to parse error responses? Couldn't we just rely on status codes? Or do you have evidence of Google responding 200 even when some error occured? Or am I missing something?

jpillora commented 10 years ago

Well you can have misformatted fields, missing fields, and few other cases. I would imagine that these would all come under 400, and it would be nice to provide these errs to the user. I guess in the meantime, status code will do. The source is reasonably simple, PR :) ?

mxmz commented 10 years ago

Actually, it turns out that this API does respond 200 with XML content under some error conditions, like ill-formed XML input or invalid values. Note that, if you add "alt=json", the Content-Type will be "application/json", but the body will still be XML (sic). When status code != 200, the Content-Type is text/html and body may or may not be a complete HTML document. Sometimes it's just a bare string.

jpillora commented 10 years ago

Okay, so it seems like some time will need to be taken to ensure this is done right. Will flag this as awaiting a PR as I won't have much time in next few months