Custom Errors¶
Service code may return custom error code and/or error message using the API documented below. The API also supports returning an HTTP status code along with the error code/message. The following sample service demonstrates possible usages of the custom error API:
package com.mbaas;
import com.backendless.exceptions.BackendlessException;
import com.backendless.servercode.IBackendlessService;
public class ErrorService implements IBackendlessService
{
public void generateCustomError()
{
String errorMessage = "I am a specific error message";
String errorCode = "245";
throw new BackendlessException( errorMessage, errorCode );
}
public void generateCustomErrorWithHTTPstatusCode()
{
String errorMessage = "I am a specific error message";
String errorCode = "245";
int httpStatusCode = 500;
throw new BackendlessException( errorMessage, errorCode, httpStatusCode );
}
}