Ticket #790 (closed Enhancement: fixed)

Opened 7 years ago

Last modified 7 years ago

Webservice: include exception info in error responses

Reported by: jri Owned by: jri
Priority: Major Milestone: Release 4.6
Component: DeepaMehta Standard Distribution Version: 4.5
Keywords: Cc: dgf, Malte, JuergeN
Complexity: 3 Area: Application Framework / API
Module: deepamehta-webservice

Description

When an exception occurs at server-side the HTTP response should include information about the error in the message body. The Webclient should present the error to the user in some way.

This is also a requirement for #442.

Change History

comment:1 Changed 7 years ago by jri

  • Status changed from new to accepted

comment:2 Changed 7 years ago by Jörg Richter <jri@…>

In 25c442b7dbb72445861a821e43f7f53f3068eb3e/deepamehta:

Webservice: include info in error response (#790).

When a HTTP request triggers an exception the response contains error information.
The message body is of type application/json and contains a JSON object then:

{
    "exception": "<exception class name>",
    "message": "...",
    "causes": [
        {
            "exception": "<exception class name>",
            "message": "..."
        },
        {
            "exception": "<exception class name>",
            "message": "..."
        },
        ...
    ]
}

The top-level exception is included directly, then an array with the chain of cause-exceptions follows.

See #790.

comment:3 Changed 7 years ago by Jörg Richter <jri@…>

In 5a8115b4d050ce123b26318e8c6644ff47151676/deepamehta:

Webservice fix: generating error responses (#790).

See #790.

comment:4 Changed 7 years ago by Jörg Richter <jri@…>

In b90d4a49190bcf5db4093d083af102e04bb30d94/deepamehta:

Webservice: change error response format (#790).

The error JSON response is a recursive object.
The final cause exception has no cause property.

{
    "exception": "<exception class name>",
    "message": "...",
    "cause": {
        "exception": "<exception class name>",
        "message": "...",
        "cause": {
            "exception": "<exception class name>",
            "message": "..."
        }
    }
}

This format reflects a Java exception more "naturally".

See #790.

comment:5 Changed 7 years ago by Jörg Richter <jri@…>

In f352bacdf548ef2a8eab68d90289ec052eabda5f/deepamehta:

Webclient: report error responses to user (#790).

When the RESTClient receives an error response the error is reported to the Webclient user via an alert box. The alert box displays the message and class name of the (Java) exception occurred at server-side, as well as all the cause-exceptions.

CHANGES

RestClient? API:

The developer can pass an error handler to the RESTClient by setting the on_error property in the config object when instantiating the RESTClient. In cases of an error the RESTClient calls this handler and passes an exception object:

{
    exception: "<exception class name>",
    message: "...",
    cause: {
        exception: "<exception class name>",
        message: "...",
        cause: {
            exception: "<exception class name>",
            message: "..."
        }
    }
}

Note: the final cause exception has no cause property.

See #790.

comment:6 Changed 7 years ago by Jörg Richter <jri@…>

In 9a25cc2ed31f91e57f057398b2897e6c6b816cde/deepamehta:

Webclient fix: throw RESTClient exception (#790).

See #790.

comment:7 Changed 7 years ago by Jörg Richter <jri@…>

In 2feb14a45b4f394a3829dc8c19752a16afd3f73b/deepamehta:

RESTClient: handle arbitrary error entity (#790).

The RESTClient handles arbitrary error response entities.

The Webclient's error alert box displays a response entity which is a JSON represented Java exception in a proper layout. Other JSON entities and non-JSON entities are displayed unformatted (as a fallback).

For server-side developers:

To generate a standard 500 (Server Error) response with the JSON representation of a Java exception just throw a RuntimeException?.

To generate an error response with a custom status code and/or custom entity throw a WebApplicationException?.

CHANGES

The on_error RESTClient config property is renamed to on_request_error.
The parameter passed to the error callback is the error response, an object with 4 properties:

content_type -- (string)
content -- (string)
status_code -- (number)
status_text -- (string)

See #790.

comment:8 Changed 7 years ago by Jörg Richter <jri@…>

In 44927ad4bfd83b958fa2b95afa50a31b4b9b3802/deepamehta:

RESTClient: per-request error handler (#790).

CHANGES

1 method changed in RESTClient:

dm4c.restc.request(method, uri, data, callback, headers, response_data_type, on_error)

New is the 7th (optional) parameter, "on_error": the "per-request error handler" to be invoked when the request fails (a function). One argument is passed: the error response (same as with the "global error handler").
The per-request error handler can prevent the global error handler from being invoked by returning false.

See #790.

comment:9 Changed 7 years ago by jri

  • Status changed from accepted to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.