Skip to content

Instantly share code, notes, and snippets.

@agusrichard
Created November 27, 2021 08:12
Show Gist options
  • Save agusrichard/cd95dd9f69c8bf08cecc068fd4eaa203 to your computer and use it in GitHub Desktop.
Save agusrichard/cd95dd9f69c8bf08cecc068fd4eaa203 to your computer and use it in GitHub Desktop.
const axios = require('axios')
const express = require('express')
const app = express()
app.get('/', async (req, res) => {
try {
await axios.get('http://localhost:3000')
res.send('Hello World!')
} catch (error) {
const status = error.response.status
if (status === 404) {
res.send('Not found')
} else if (status === 400) {
res.send('Bad request')
} else {
res.send('Something went wrong')
}
}
})
app.listen(5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment