Skip to content

Commit

Permalink
Fix city does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
sandaun committed Feb 16, 2019
1 parent 96c299e commit 3c33f22
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ router.post('/', (req, res, next) => {

// Make a request for a user with a given ID
axios.get(url)
.then(({ data }) => {
.then((response) => {
// handle success
console.log(data);
const { data } = response;
console.log(response);
res.render('weather', { title: city, data });
})
.catch((error) => {
// handle error
console.log(error);
next();
res.render('error', { title: 'Not found', city, error });
});
});

Expand Down
5 changes: 2 additions & 3 deletions views/error.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
<h1><%= message %></h1>
<h2><%= error.status %></h2>
<pre><%= error.stack %></pre>
<h1> <%= city %> does not exist</h1>
<a href="/api">Try again</a>
2 changes: 1 addition & 1 deletion views/weather.ejs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h2> <%= data.name %> </h2>
<h1> <%= data.name %> </h1>
<p>The weather in <%= data.name %> is <%= Math.floor(data.main.temp - 273) %> degrees Celsius</p>
<a href="/api">Mirar otra ciudad</a>

0 comments on commit 3c33f22

Please sign in to comment.