Options
All
  • Public
  • Public/Protected
  • All
Menu

Class CreateException

Error raised when factory is not able to create requested component.

see

InternalException (in the PipServices "Commons" package)

see

ApplicationException (in the PipServices "Commons" package)

Hierarchy

  • InternalException
    • CreateException

Index

Constructors

constructor

  • new CreateException(correlationId?: string, messageOrLocator: any): CreateException
  • Creates an error instance and assigns its values.

    Parameters

    • Default value correlationId: string = null
    • messageOrLocator: any

      human-readable error or locator of the component that cannot be created.

    Returns CreateException

Properties

category

category: string

Defines what category of exceptions this exception belongs to.

cause

cause: string

Additional information about the cause of the exception.

code

code: string

Every error needs a unique code by which it can be identified. Using this code, we can select which localized error messages to use and what to display in the UI.

correlation_id

correlation_id: string

Unique business transaction id to trace calls across components. Important field for microservices, as it allows us to tie an exception to a specific business transaction.

details

details: StringValueMap

This field is used to add additional information to localized error message strings.

For example, if we received an ObjectNotFoundException (general error) when searching for an object via its id, the id by which the object was not found can be added as a detail. This allows us to add additional details to localized error messages. Resulting error message format: “(Localized error's text) - id: (id)”

message

message: string

This field stores the message or description that was contained in the original error. Errors' messages are always in English. However, using this class's 'code' and 'details' fields, we can create localized versions of the error's message and use them instead in the UI.

stack_trace

stack_trace: string

Stack trace of the exception.

status

status: number

Used when sending over the REST interface, so that we know what HTTP status code to raise.

Static message

message: string

Static name

name: string

Static Optional stack

stack: string

Methods

getCauseString

  • getCauseString(): string
  • Returns additional information about the cause of the exception.

    Returns string

getStackTraceString

  • getStackTraceString(): string
  • Returns the stack trace of the exception.

    Returns string

setCauseString

  • setCauseString(value: string): void
  • Sets additional information about the cause of the exception.

    Parameters

    • value: string

    Returns void

setStackTraceString

  • setStackTraceString(value: string): void
  • Sets the stack trace of the exception.

    Parameters

    • value: string

    Returns void

withCause

  • withCause(cause: Error): ApplicationException
  • Sets the cause of the exception and returns the resulting ApplicationException. The 'cause' field contains additional information about the cause of the exception.

    Parameters

    • cause: Error

    Returns ApplicationException

withCode

  • withCode(code: string): ApplicationException
  • Sets the code of the exception and returns the resulting ApplicationException. Every error needs a unique code by which it can be identified. Using this code, we can select which localized error messages to use and what to display in the UI.

    Parameters

    • code: string

    Returns ApplicationException

withCorrelationId

  • withCorrelationId(correlation_id: string): ApplicationException
  • Sets the correlation ID of the exception and returns the resulting ApplicationException. The correlation ID ties an exception to a specific business transaction.

    Parameters

    • correlation_id: string

    Returns ApplicationException

withDetails

  • withDetails(key: string, value: any): ApplicationException
  • Sets the details of the exception and returns the resulting ApplicationException. Details are used to add additional information to localized error message strings.

    Parameters

    • key: string
    • value: any

    Returns ApplicationException

withStackTrace

  • withStackTrace(stackTrace: string): ApplicationException
  • Sets the stack trace of the exception and returns the resulting ApplicationException.

    Parameters

    • stackTrace: string

    Returns ApplicationException

withStatus

  • withStatus(status: number): ApplicationException
  • Sets the status of the exception and returns the resulting ApplicationException. The 'status' field is used when sending exceptions over the REST interface, so that we know what HTTP status code to raise.

    Parameters

    • status: number

    Returns ApplicationException

wrap

  • wrap(cause: any): ApplicationException
  • Wrapping allows us to transform general exceptions into ApplicationExceptions.

    This method does the following:

    • attempts to unwrap Seneca and restify exceptions from the parameter 'cause' using the static method unwrapError (if they are present).
    • checks whether 'cause' is an ApplicationException (if it is, then no additional wrapping is done).
    • if the 'cause' parameter contains an unknown exception, then the cause field of this ApplicationException object is set to the original exception (the 'cause' parameter's 'message' field).

    The third point of this list is used in the following way: when an unknown exception is raised, the exception's type can be determined, a category of ApplicationExceptions that is closest to the exception's type can be chosen from the ones available, after which the unknown exception can be wrapped around the chosen type of ApplicationException. This is done for unifying exceptions, as it is challenging to process a wide variety of unknown exceptions. Wrapping unknown exceptions around existing ones allows us to categorize them and be "in the ballpark".

    see

    unwrapError

    Parameters

    • cause: any

      the exception that is to be wrapped around this ApplicationException object.

    Returns ApplicationException

    the 'cause' parameter as an ApplicationException (if it is one) or this ApplicationException object with 'this.cause' set to the 'cause' parameter's 'message' field.

Static unwrapError

  • unwrapError(error: any): any
  • Used to unwrap Seneca exceptions and restify exceptions.

    Parameters

    • error: any

      error that may contain Seneca or restify exceptions.

    Returns any

    For Seneca exceptions: error.orig. For restify exceptions: error.body.

Static wrapError

  • wrapError(error: ApplicationException, cause: any): ApplicationException
  • Static method that is identical to the non-static method wrap. Wraps 'cause' around the ApplicationException passed as 'error', instead of itself (this).

    see

    wrap

    Parameters

    • error: ApplicationException

      ApplicationException that has been chosen for wrapping.

    • cause: any

      the exception that is to be wrapped around the 'error' parameter.

    Returns ApplicationException

    the 'cause' parameter as an ApplicationException (if it is one) or the parameter 'error' with its 'cause' field set to the 'cause' parameter's 'message' field.

Generated using TypeDoc