Uploaded image for project: 'translate5'
  1. translate5
  2. TRANSLATE-1068

Improve REST API on wrong usage

    XMLWordPrintable

Details

    • Critical
    • Hide
      6.7.1: fix for special use case when authenticating against API session endpoint
      6.7.0: API requests (expect file uploading requests) can now understand JSON in raw body, additionally to the encapsulated JSON in a data form field. Also a proper HTTP error code is sent when providing invalid JSON.
      Show
      6.7.1: fix for special use case when authenticating against API session endpoint 6.7.0: API requests (expect file uploading requests) can now understand JSON in raw body, additionally to the encapsulated JSON in a data form field. Also a proper HTTP error code is sent when providing invalid JSON.

    Description

      problem

      Currently there are several pitfalls on using the API for users using it the first time.
      For example that all data must be packed as data object etc.
      Some users are trying to make an ordinary post, with single data fields.
      This is currently not supported, but gives error messages like

      ZfExtended_Log on xzy.translate5.net: exception 'Zend_Exception' with message 'Creating default object from empty value; File: /webs/xzy.translate5.net/library/ZfExtended/Controllers/UserController.php; Line: 178; errno: 2' in /webs/xzy.translate5.net/library/ZfExtended/Resource/ErrorHandler.php:122

      Also provide PHP curl examples, not only bash curl examples.

      Another problem are different error structures. For example on PUT a user, an invalid emails has a different error structure as an invalid ID (in the PUT data, not in the URL) for example.

      Or what is also a problem: some fields defined as boolean in the documentation sends true|false others 0|1 integers instead. This should be consistent!

      solution

      This should be captured in general, if there is no data object just give a brief exception so that the user gets the info that he is sending the wrong data.

      Also check if the json_decode call in RestController::decodePutData is producing decode errors, currently this results also in the above message. 
      JSON decode errors can happen for example by not decoding the payload containing a "&" (Ampersand) although the content-type is www-form-encoded which sais that the content should be encoded!

      solution v2:

      Make the API more flexible:

      • if there is no data variable check plain content, is the plain content JSON use that
      • If there is no plain content but multiple variables, try to use them as input → will fail if one field is dedicated to use JSON, how to deal that?
      • File Uploads: For most API users (probably all) it would be much easier if the file uploads could be provided as string data in the JSON instead as multipart boundary

      Attachments

        Issue Links

          Activity

            People

              tlauria Thomas Lauria
              tlauria Thomas Lauria
              Leon Kiz
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: