Defining Fault Messages for REST Service Operations

This section describes how to specify fault messages for REST service operations.

Understanding Fault Messages for REST Service Operations

You can specify fault messages for service operations for error handling.

Note the following about fault messages:

  • You cannot add fault messages to asynchronous service operations.

  • Fault messages must be nonrowset-based messages, container messages, or document messages. Fault messages cannot be rowset-based messages.

Understanding Fault Message HTTP Return Status Codes for REST Service Operations and the OnError Method

The system recognizes and uses fault message HTTP status codes only if the fault Message is used in the OnError method. Simply using the fault message within the OnRequest method will be treated like any other message.

Understanding Fault Message HTTP Return Status Codes and Service System Status for Provider REST Service Operations

If you specify fault messages for provider REST service operations, the service system status impacts the HTTP return status codes as follows:

Field or Control Description

Production

If the service system status is set to Production, any errors by the framework or that are not part of a fault message defined in the OnError method will result in an HTTP status code returned of 500 with the errors not included in the payload.

If a fault message is defined on the service operation and invoked within the OnError method, then the status code of 400 (or any other status code set for the fault) will be returned as the HTTP status code along with the error message.

Development

If the service system status is set to Development, any errors by the framework or that are not part of a fault message defined in the OnError method will result in an HTTP status code returned of 500 with the error message included in the payload.

If the fault message is defined on the service operation and invoked within the OnError method, the status code of 400 (or any other status code set for the fault) will be returned as the HTTP status code along with the error message.

Defining Fault Messages for REST Service Operations

To define a fault message for a REST service operation:

  1. Locate the Default Service Operation Version section on the Service Operations – General tab.

  2. Click the Add Fault Type button.

    A new row appears in which to specify a message. Note that the Type field in the new row displays Fault.

  3. In the Message.Version field, enter the message name, or click the Lookup button to search for one.

    After you select the message, you can click the View Message link to view the message.

  4. From the Content-Type drop-down list, select the MIME content type of the message.

    The valid values are:

    • application/json

    • application/xml

    • text/xml

    • text/plain

    • text/html

  5. (Optional) Define optional content-types.

    To define optional content-types:

    1. Click the Optional Content-Types link.

      The Set Content Type page appears.

    2. Type in any content type or select a content type from the Content-Type drop-down list.

      The valid values from the Content-Type drop-down list are the same as those listed in Step 4.

    3. To add additional content-types, click the Add Row button (+) and type in a content type or select a content-type from the list.

    4. Click the OK button.

      The Service Operations – General page appears.

  6. From the Status drop-down list, select a status code. The default and only value is 400.

  7. Click the Save button.

To delete a fault message, in the Default Service Operation Version section, click the Delete Fault Type button. Then click the Save button.