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

Enhance REST output when failing to save/create a draft

    XMLWordPrintable

Details

    • Icon: Story Story
    • Resolution: Fixed
    • Icon: High High
    • 1.5.0
    • 2015.07, 1.3.1, 1.4.1
    • Platform > REST API v2
    • 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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            damien.pobel-obsolete@ez.no 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