IBackendlessService - how to return error information - BackendlessException?


I’m creating a number of custom business logic services and it isn’t clear how errors are intended to be returned. Say my business logic verifies the passed data before acting on it, what is the recommended way to return an error status and message in a way that will be handled by the client SDK (so it appears as a Fault).

Should I be throwing a new BackendlessException? It seems the most likely constructor I should use is:

public BackendlessException(String code, String message, int httpStatusCode)

but I can’t find any documentation about this.

If I do use BackendlessException I assume I can choose any HTTP status code which makes sense for the issue I’ve encountered?


Hi Wain,

BackendlessException has constructors accepting HTTP status code:

public BackendlessException( String message, int httpStatusCode )


public BackendlessException( String code, String message, int httpStatusCode )

You can use them or create BackendlessException in any other way and then just use setHttpStatusCode( int ) method to set HTTP status code of the error.

Thanks Sergey,

I’ve experimented a little since posting the question having seen nothing else that looked sensible to do in the libs, and using the swagger interface I did get my desired HTTP status and message. The code always looked to come out as 0 and the mime type as text/plain however

When using the code generation iOS SDK will the error information actually be returned into the Fault parameter and include the error code?

There are two codes in constructor: the one is HTTP status code (which is the last one) - it is used as an HTTP response status code, and the other one is “code”, which is the fault code you have become familiar with when doing requests to the backend.

So for usage within iOS SDK I would recommend you to set the latter one, the fault code, and then retrieve and handle it in your iOS application.


just a heads-up, in the current implementation a REST call would return the error as a text/plain response. We’re changing it to JSON and the response’s content-type will be application/json. This may impact your app. When do you plan to release it to app store?


Hi Mark, thanks

At the moment I’m not planning to use the REST interface for anything other than swagger, I’ll be using the iOS & Android client SDKs. Production release is likely more than a month away currently.

This is dependent on SDK issues though as I’ve reported a couple of issues now and that could cause me to move towards plain REST. I’m interested in helping with the client SDK (for iOS at least) if you’d entertain it?

We would welcome any help you can offer! Is there a particular area of the SDK that would be of an interest to you?