Announcement

Collapse
No announcement yet.

Unexpected token error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unexpected token error

    I am receiving this error from the response transformer:

    SCRIPT SOURCE: response
    SOURCE CODE:
    500: }
    501: eval('importPackage(' + Packages.java.lang.Class.forName(className).getPac kage().getName() + ')');
    502: }
    503: }
    504: function doScript() {
    505: msg = JSON.parse(connectorMessage.getResponseTransformed Data());
    506: function doTransform() {
    507:
    508:
    509: if (response.getNewMessageStatus() == 'SENT') {
    LINE NUMBER: 505
    DETAILS: SyntaxError: Unexpected token: <
    Attached Files

  • #2
    If you look at your actual response data, you're probably getting an HTTP error message instead of the JSON you're expecting.

    If you need to be able to handle that gracefully, you'll have to change the inbound type of your response transformer to Raw and manually JSON.parse(msg) after you verify you didn't get an error response.

    Comment


    • #3
      It seems that I'm unable to get that far - being able to view the response data.

      I have this code in the Response Transformer to view it:

      var ResponseMessage = response.getMessage();
      logger.info("ResponseMessage: "+ ResponseMessage.toString());
      var ResponseXML = new XML(ResponseMessage.toString());
      logger.info("Response XML=" + ResponseXML.toString());
      globalChannelMap.put('RM', ResponseFactory.getSentResponse(ResponseXML));

      , but it doesn't get executed because the channel errors out before then:

      SOURCE CODE:
      500: }
      501: eval('importPackage(' + Packages.java.lang.Class.forName(className).getPac kage().getName() + ')');
      502: }
      503: }
      504: function doScript() {
      505: msg = JSON.parse(connectorMessage.getResponseTransformed Data());
      506: function doTransform() {
      507:
      508:
      509: var ResponseMessage = response.getMessage();
      LINE NUMBER: 505
      DETAILS: SyntaxError: Unexpected token: <

      Comment


      • #4
        Did you try looking in the message browser? I think it should show up as long as you have your channel's storage set to production or development.

        If not, try changing your response transformer's inbound data type to Raw. In that case msg will just be a string, which you should be able to log.

        Comment


        • #5
          This is the message I received in the message browser:

          ERROR: Received error response from HTTP server.

          <WSResult>
          <Result>
          <SessionID>46a7ef52-2fbd-4b8e-ad0a-e3c10989db79</SessionID>
          <Code>500</Code>
          <Description>INTERNAL_SERVER_ERROR</Description>
          <ErrorList count="1">
          <Error>Not authorised to view the result
          </Error>
          </ErrorList>
          </Result>
          </WSResult>

          I accessed the Linux shell on the Mirth Appliance and ran a curl command:

          curl -v -X POST -H "Content-Type:application/json" -d '{"UserName":"ABC","Password":"XYZ"}' "https://www.website.com"

          I received this:

          * Trying 12.34.567.89...
          * Connected to www.website.com (12.34.567.89) port 443 (#0)
          * ALPN, offering http/1.1
          * Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@ STRENGTH
          * error setting certificate verify locations:
          CAfile: /etc/pki/tls/certs/ca-bundle.crt
          CApath: none
          * Closing connection 0
          curl: (77) error setting certificate veryify locations:
          CAfile: /etc/pki/tls/certs/ca-bundle.crt
          CApath: none

          So it looks like our appliance has a CA certificate issue (I can successfully run the command from another, unrelated UNIX box).

          Comment

          Working...
          X