Uploaded image for project: 'Commons - Script'
  1. Commons - Script
  2. SCRIPT-10

No way to throw a ResourceException from groovy

    Details

    • Type: Improvement
    • Status: Resolved
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.4.0
    • Fix Version/s: 1.5.0
    • Component/s: groovy
    • Labels:
    • Sprint:
      OpenIDM Sprint 41
    • Cases:
    • Support Ticket IDs:

      Description

      In Javascript, errors can be thrown like so:

                          throw { "code": 400, "message": "Unable to build string from decoded response", "detail": response };
      

      Our Groovy implementation does not provide an equivalent way to do this. "throw" in groovy needs to be passed a proper exception object, and any such thrown exception will be treated in the same way - as a generic org.forgerock.json.resource.InternalServerErrorException with the message of "" (empty string). Even throwing exceptions like this don't work, because they are always wrapped in a ScriptThrownException:

      import org.forgerock.json.resource.ResourceException
      
      throw new ResourceException(404)
      

      Groovy scripts must be able to provide the same sorts of failure responses that Javascript can; without this, it is much less useful of an environment to work in.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                brmiller Brendan Miller
                Reporter:
                jake.feasel Jake Feasel
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: