All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.backendless.servercode.services.CustomServiceException Maven / Gradle / Ivy

The newest version!
package com.backendless.servercode.services;

import com.backendless.commons.exception.BackendlessExceptionMessage;
import com.backendless.commons.exception.BackendlessServerException;
import com.backendless.commons.exception.ExceptionWrapper;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: Eugene Chipachenko
 * Date: 11.07.14
 * Time: 13:37
 */
public class CustomServiceException extends BackendlessServerException
{
  private int httpStatusCode = 400;
  private Map httpResponseHeaders = new HashMap<>();

  public CustomServiceException()
  {
  }

  public CustomServiceException( BackendlessExceptionMessage message )
  {
    super( message );
  }

  public CustomServiceException( BackendlessExceptionMessage message, Throwable t )
  {
    super( message, t );
  }

  public CustomServiceException( int code, String message )
  {
    super( new Messages( code, message ) );
  }

  public CustomServiceException( ExceptionWrapper e )
  {
    this( e.getCode(), e.getExceptionMessage() == null ? e.getExceptionClass() : e.getExceptionMessage() );
    if (e.getHttpStatusCode() > 0)
      this.httpStatusCode = e.getHttpStatusCode();
  }

  public CustomServiceException setHttpStatusCode( int httpStatusCode )
  {
    this.httpStatusCode = httpStatusCode;
    return this;
  }

  public Map getHttpResponseHeaders()
  {
    return httpResponseHeaders;
  }

  public CustomServiceException setHttpResponseHeaders(
          Map httpResponseHeaders )
  {
    if( httpResponseHeaders != null )
      this.httpResponseHeaders = httpResponseHeaders;
    return this;
  }

  public int getHttpStatusCode()
  {
    return httpStatusCode;
  }

  public void setHttpStatusCode( short httpStatusCode )
  {
    this.httpStatusCode = httpStatusCode;
  }

  public static class Messages extends BackendlessExceptionMessage
  {
    protected Messages( int code, String message )
    {
      super( code, message );
    }

    public static Messages SERVICE_COMMON_ERROR( String errorDescription )
    {
      return new Messages( 14000, errorDescription );
    }

    public static final Messages SERVICE_NOT_FOUND = new Messages( 14001, "Service not found" );
    public static final Messages SERVICE_METHOD_NOT_FOUND = new Messages( 14002, "Service method not found" );
    public static final Messages CAN_NOT_REMOVE_SERVICE = new Messages( 14006, "Cannot delete a service which is published to marketplace. Remove the service from the marketplace first, then try deleting again" );
    public static final Messages SERVICE_ALREADY_SUSPENDED = new Messages( 14007, "Service already suspended" );
    public static final Messages ACCESS_DENY = new Messages( 14008, "Access denied" );
    public static final Messages INCORRECT_NUMBER_OF_ARGS = new Messages( 14009, "Incorrect number of arguments on method invoke" );
    public static final Messages PERSISTENCE_LEVEL_FAIL = new Messages( 14010, "Cannot persist service information" );
    public static final Messages METHOD_NAME_NOT_VALID = new Messages( 14013, "\"OperationId\" must contain only letters, numbers and underscores, must not begin with number or underscore, must contain only 45 symbols." );
    public static final Messages METHOD_NAME_NOT_UNIQUE = new Messages( 14014, "Method name in service description file must be unique." );
    public static final Messages CAN_NOT_GENERATE_SDK_CODE = new Messages( 14015, "Can't generate SDK code for this service or platform. Make sure the service class or the classes it uses do not conflict with the table names" );
    public static final Messages CAN_NOT_CHANGE_ACL = new Messages( 14016, "Can't change ACL. Internal Error." );
    public static final Messages CAN_NOT_CREATE_GENERIC_SERVICE = new Messages( 14017, "Can't create generic service" );
    public static final Messages CAN_NOT_CREATE_IMPORTED_SERVICE = new Messages( 14018, "Can't create imported service" );
    public static final Messages SERVICE_VERSION_NOT_FOUND = new Messages( 14019, "Service not found" );
    public static final Messages CAN_NOT_GENERATE_XML_SCHEMA = new Messages( 14020, "Can not generate xml schema document for codegen" );
    public static final Messages DEBUGGER_DISCONNECTED = new Messages( 14021, "Debugging utility is disconnected" );
    public static final Messages NOT_FOUND_RESOURCES = new Messages( 14028, "Not found resources, please check you request" );

    public static Messages NOT_VALID_SERVICE_DESCRIPTION( String filePath )
    {
      return new Messages( 14011, "This is not a valid service description: '" + filePath + "'." );
    }
    public static Messages CAN_NOT_PARSE_GENERIC_SERVICE( String message )
    {
      return new Messages( 14012, "Can not parse generic service: " + message );
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy