[OPENIDM-4919] Script eval action doesn't handle ResourceExceptions thrown by scripts Created: 21/Dec/15  Updated: 27/Jun/16  Resolved: 27/Jun/16

Status: Closed
Project: OpenIDM
Component/s: Module - Scripting
Affects Version/s: OpenIDM 4.0.0, OpenIDM 4.5.0
Fix Version/s: OpenIDM 4.5.0

Type: Bug Priority: Major
Reporter: Jake Feasel Assignee: Brendan Miller
Resolution: Fixed Votes: 0
Labels: release-notes
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to SCRIPT-10 No way to throw a ResourceException f... Resolved

 Description   

As originally noted here: https://bugster.forgerock.org/jira/browse/SCRIPT-10?focusedCommentId=64143&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-64143

Calls to the script service which throw an exception are not handled properly:

curl --data '{ "type": "groovy", "source": " import org.forgerock.json.resource.ResourceException; throw new ResourceException(404, \"It aint there\").setDetail(new org.forgerock.json.JsonValue([a:1]))" }' -u openidm-admin:openidm-admin -k -X POST -H "Content-type: application/json" https://localhost:8443/openidm/script?_action=eval

Produces this:

{"code":500,"reason":"Internal Server Error","message":"It aint there"}

Note the lack of the detail and the wrong code. Similarly, JS doesn't work properly (see link for details)

Those same scripts work fine when executed as part of a custom endpoint, defined (for example) like so:

{
    "type" : "groovy",
    "source" : " import org.forgerock.json.resource.ResourceException; import org.forgerock.json.JsonValue; throw new ResourceException(404, \"It ain't there\").setDetail(new JsonValue([\"var\": \"blah\", \"complexDetailObject\" : [\"detail1\",\"detail2\"]]))"
}


 Comments   
Comment by Brendan Miller [ 22/Dec/15 ]

Added catch (ScriptThrownException e) with proper conversion to ResourceException.

Comment by Laurent Bristiel [X] (Inactive) [ 13/Jan/16 ]

tested OK in OpenIDM version "4.1.0-SNAPSHOT" (revision: d89be50)
Automated in testcases/functional/scripting/javascript/general/raising_exception_in_script_via_payload.robot

Comment by Lana Frost [ 27/Jun/16 ]

Reopening to add release-notes label

Generated at Sun Sep 27 20:16:55 UTC 2020 using Jira 7.13.12#713012-sha1:6e07c38070d5191bbf7353952ed38f111754533a.