[Bug 863746] Optimize error handling and HTTP error codes in API calls

Ref: https://bugzilla.mozilla.org/show_bug.cgi?id=863746