From 7f0ac30d6250dc591b3217a238e445c7d5e24785 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Singh Date: Mon, 19 Nov 2018 20:02:45 +0530 Subject: [PATCH 1/2] replace promise with async await and used try catch for error handle --- samples/app.js | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/samples/app.js b/samples/app.js index 2f4866e0e..461a1f151 100644 --- a/samples/app.js +++ b/samples/app.js @@ -26,26 +26,25 @@ const express = require('express'); const got = require('got'); const app = express(); -const DISCOVERY_URL = 'https://www.googleapis.com/discovery/v1/apis'; +const DISCOVERY_URL = 'https://www.googleapis.com/discovery/v1/apis1'; // This incoming HTTP request should be captured by Trace -app.get('/', (req, res) => { - // This outgoing HTTP request should be captured by Trace - got(DISCOVERY_URL, { json: true }) - .then((response) => { - const names = response.body.items.map((item) => item.name); - - res - .status(200) - .send(names.join('\n')) - .end(); - }) - .catch((err) => { - console.error(err); - res - .status(500) - .end(); - }); +app.get('/', async (req, res) => { + // This outgoing HTTP request should be captured by Trace + try { + const { body } = await got(DISCOVERY_URL, { json: true }); + const names = body.items.map((item) => item.name); + res + .status(200) + .send(names.join('\n')) + .end(); + } + catch (err) { + console.error(err); + res + .status(500) + .end(); + } }); // Start the server From 413d1b4dc3313d42fde56fe3c26ec1a43280ab8a Mon Sep 17 00:00:00 2001 From: Praveen Kumar Singh Date: Tue, 20 Nov 2018 18:07:38 +0530 Subject: [PATCH 2/2] rectify DISCOVERY_URL --- samples/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/app.js b/samples/app.js index 461a1f151..a7027597e 100644 --- a/samples/app.js +++ b/samples/app.js @@ -26,7 +26,7 @@ const express = require('express'); const got = require('got'); const app = express(); -const DISCOVERY_URL = 'https://www.googleapis.com/discovery/v1/apis1'; +const DISCOVERY_URL = 'https://www.googleapis.com/discovery/v1/apis'; // This incoming HTTP request should be captured by Trace app.get('/', async (req, res) => {