Indentation fixes.
Removed trailing whitespace.
Throw an exception on API error.
Added extra data to API error object.

- error code (HTTP code)
- error message (if any)