Uploaded image for project: 'eZ Publish / Platform'
  1. eZ Publish / Platform
  2. EZP-24853

Enhance REST output when failing to save/create a draft

    Details

    • Type: Story Story
    • Status: Closed
    • Priority: High High
    • Resolution: Fixed
    • Affects Version/s: 2015.07, 1.3.1, 1.4.1
    • Fix Version/s: 1.5.0
    • Component/s: Platform > REST API v2
    • Labels:
      None

      Description

      Right now, if a draft can not be saved/created, the REST API generates a 400 response with the following content:

      {
          "ErrorMessage": {
              "_media-type": "application\/vnd.ez.api.ErrorMessage+json",
              "errorCode": 400,
              "errorMessage": "Bad Request",
              "errorDescription": "Value for required field definition 'user_account' with language 'eng-GB' is empty",
              "trace": "<stack trace>",
              "file": "\/home\/dp\/dev\/ezplatform\/vendor\/ezsystems\/ezpublish-kernel\/eZ\/Publish\/Core\/REST\/Server\/Controller\/Content.php",
              "line": 248
          }
      }
      

      It's hard for a REST API consumer (PlatformUI for instance) to know what exactly went wrong and in addition only the first validation error is described. It would be nice if the REST API could provide more details in a structured way. For instance, when a required field (user_account) is not provided and a invalid content is provided (in an email field), the response could be something like:

      {
          "ErrorMessage": {
              "_media-type": "application\/vnd.ez.api.ErrorMessage+json",
              "errorCode": 400,
              "errorMessage": "Bad Request",
              "errorDescription": "Validation fails on several fields",
              "errorDetails": {
                      "fields": {
                              "user_account": {
                                  type: "empty",
                                  message: "Value for required field definition 'user_account' with language 'eng-GB' is empty"
                              },
                              "email": {
                                  type: "syntax",
                                  message: "The provided email is invalid"
                              }
                      }
              }
              "trace": "<stack trace>",
              "file": "\/home\/dp\/dev\/ezplatform\/vendor\/ezsystems\/ezpublish-kernel\/eZ\/Publish\/Core\/REST\/Server\/Controller\/Content.php",
              "line": 248
          }
      }
      

      error details in errorDetails.fields are indexed by field definition identifier and the type values are just examples and are to be defined.

        Issue Links

          Activity

          Hide
          Gunnstein Lye added a comment - - edited

          Currently it throws immediately when something fails, either a ContentValidationException (required field is empty) or a ContentFieldValidationException (a field is invalid), though they are treated the same way (forwarded as a BadRequestException).

          We can catch these and collect them in an array, and throw a BadRequestException with all of them like Damien suggests, I think.

          Edit: We're in fact already doing this for ContentFieldValidationExceptions, we'd just need to do the same for ContentValidationExceptions.

          Show
          Gunnstein Lye added a comment - - edited Currently it throws immediately when something fails, either a ContentValidationException (required field is empty) or a ContentFieldValidationException (a field is invalid), though they are treated the same way (forwarded as a BadRequestException). We can catch these and collect them in an array, and throw a BadRequestException with all of them like Damien suggests, I think. Edit: We're in fact already doing this for ContentFieldValidationExceptions, we'd just need to do the same for ContentValidationExceptions.
          Hide
          Gunnstein Lye added a comment - - edited

          Proposal: https://github.com/ezsystems/ezpublish-kernel/pull/1734

          Edit: Closed, requires BC break - must wait until v7.0.
          Edit: Reopened, possible solution in sight.

          Show
          Gunnstein Lye added a comment - - edited Proposal: https://github.com/ezsystems/ezpublish-kernel/pull/1734 Edit: Closed, requires BC break - must wait until v7.0. Edit: Reopened, possible solution in sight.
          Show
          Gunnstein Lye added a comment - Merged in master (v6.5): https://github.com/ezsystems/ezpublish-kernel/commit/c9f24fce39332412e88de88fdf0086b5f0521373
          Hide
          Gunnstein Lye added a comment -

          QA: Implementation is not exactly as suggested in the description, see description in PR.

          Show
          Gunnstein Lye added a comment - QA: Implementation is not exactly as suggested in the description, see description in PR.
          Hide
          Rui Silva (Inactive) added a comment -

          Tested and approved by QA for master.

          Show
          Rui Silva (Inactive) added a comment - Tested and approved by QA for master.

            People

            • Assignee:
              Unassigned
              Reporter:
              Damien Pobel (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 week, 1 day, 3 hours, 40 minutes
                1w 1d 3h 40m