From 3353fac4f74ad02e73ccb28de00c5b451b9e0c45 Mon Sep 17 00:00:00 2001 From: Perry Mitchell Date: Thu, 28 Oct 2021 14:46:37 +0300 Subject: [PATCH] Add error codes --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6471d67..a756c75 100644 --- a/index.js +++ b/index.js @@ -17,17 +17,23 @@ const handleIpRouteResults = (callback) => (error, stdout, stderr) => { if (ip) { callback(undefined, ip); } else { - callback(new Error("Unable to find ip, perhaps call while not within a Docker container"), undefined); + const error = new Error("Unable to find ip, perhaps call while not within a Docker container"); + error.code = "DOCKER_IP_NO_RESOLVE"; + callback(error, undefined); } } else if (error) { callback(error, undefined); } else if (stderr) { - callback(new Error(stderr), undefined); + const error = new Error(stderr); + error.code = "DOCKER_IP_STDERR"; + callback(error, undefined); } else { - callback(new Error("No results or feedback given"), undefined); + const error = new Error("No results or feedback given"); + error.code = "DOCKER_IP_EMPTY"; + callback(error, undefined); } };