project-lux / lux-marklogic

Code, issues, and resources related to LUX MarkLogic
Other
3 stars 2 forks source link

Account for error being undefined within the error handler #207

Open brent-hartwig opened 2 days ago

brent-hartwig commented 2 days ago

How can this be tested?

When #203 is also deployed, one can attempt to consume the /ds/lux/personRoles.mjs endpoint. If a 404 is returned, this is working. If a 500 is returned, this may not yet be deployed.


Description

The line let errorBody = external.error.toObject(); fails when external.error is undefined, leading to another error that covers up the main one.

Example of backend response when this condition is true:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>500 Internal Server Error</title>
    <meta name="robots" content="noindex,nofollow" />
    <link rel="stylesheet" href="/error.css" />
</head>

<body>
    <span class="error">
      <h1>500 Internal Server Error</h1>
      <dl>
        <dt>JS-JAVASCRIPT: let errorBody = external.error.toObject(); -- Error running JavaScript request: TypeError: Cannot read property 'toObject' of undefined</dt>
        <dd></dd>
        <dt>in /customErrorHandler.mjs, at 9:31 [javascript]</dt>
        <dd></dd>
        <dt>in /customErrorHandler.mjs [javascript]</dt>
        <dd></dd>
      </dl>
    </span>
</body>

</html>
brent-hartwig commented 2 days ago

Addressed in PR https://github.com/project-lux/lux-marklogic/pull/208. After addressing, the same request that resulted in the above 500 changed to a 404 --which is correct for the given request (i.e., the fix allowed the real error to surface).