Skip to content

Commit 526bc1a

Browse files
authored
Added Apollo Server GraphQL API error message for failed requests (aws#129)
Any expired security tokens or network connectivity errors when querying neptune resulted in a cryptic error message that was not helpful for debugging. Instead of swallowing errors, added an error catch message with rethrow to ensure that when these errors result it returns a more useful error message that will help with the debugging of the error.
1 parent e2e9346 commit 526bc1a

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ permissions and limitations under the License.
7070
neptune analytics graph and added testing
7171
documentation ([#113](https://github.com/aws/amazon-neptune-for-graphql/pull/113))
7272
* Updated query and mutation names to be less graph-specific ([#124](https://github.com/aws/amazon-neptune-for-graphql/pull/124))
73+
* Improved API error message for failed requests ([#129](https://github.com/aws/amazon-neptune-for-graphql/pull/129))
7374
* Documented custom query to filter nodes by connected nodes'
7475
properties ([#130](https://github.com/aws/amazon-neptune-for-graphql/pull/130))
7576

templates/ApolloServer/neptune.mjs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,7 @@ export async function resolveEvent(event) {
3434
if (loggingEnabled) {
3535
console.error(err);
3636
}
37-
return {
38-
"error": [{"message": err}]
39-
};
37+
throw new Error(`Failed to query Neptune: ${err.message || err}`);
4038
}
4139

4240
}

templates/queryHttpNeptune.mjs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,9 @@ export async function queryNeptune(neptuneUrl, resolvedQuery, options = {logging
7171
return jsonData;
7272
}
7373
} catch (err) {
74-
console.error("Failed to query neptune")
74+
console.error("Failed to query neptune");
7575
console.error(err);
76-
return {
77-
"error": [{"message": err}]
78-
};
79-
}
8076

77+
throw new Error(`Neptune query failed: ${err.message || err}`);
78+
}
8179
}

0 commit comments

Comments
 (0)