How to handle Salesforce REST error response in JSON (Python) -
i wondering how correctly handle salesforce error responses portal i'm developing. or more generically, how handle json error response. instance, if queried database information didn't exist, if user provided incorrect login credentials, etc. i'm looking accepted, pythonic solution problem.
thank you.
check response, if there's error, raise exception.
ideally, exception should match error message returned api, , include information returned api.
if you're writing library, let end-user decide how want proceed.
here's example of code wrote salesforce rest api wrapper:
the exception:
class soqlexception(sfdcexception): def __init__(self, errorcode, message): self.errorcode = errorcode self.message = message
and in code making request, after loading json data
.
maybe changed, salesforce used return error dict inside array:
if len(data) == 1 , u"errorcode" in data[0]: error = data[0] raise soqlexception(**error)
Comments
Post a Comment