Skip to content
Snippets Groups Projects
Verified Commit e2f385b3 authored by Erick Hitter's avatar Erick Hitter
Browse files

Return an error code when an API error occurs, rather than an empty "success"

parent 76653bdd
Branches
No related tags found
No related merge requests found
......@@ -44,27 +44,30 @@ app.post('/post', function(req, res){
console.log(parsed_url);
request(parsed_url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data = JSON.parse(body);
var temperature = data.current_observation.temperature_string;
var weatherCondition = data.current_observation.weather;
var icon_url = data.current_observation.icon_url;
var location = data.current_observation.display_location.full;
if ( error || 200 !== response.statusCode ) {
return res.sendStatus( 500 );
}
var body = {
response_type: "in_channel",
"attachments": [
{
"text": "Location: " + location + "\n"
+ "Temperature: " + temperature + "\n"
+ "Condition: " + weatherCondition,
"image_url": icon_url,
}
]
};
// Get current conditions first
var conditionData = JSON.parse( body );
var temperature = conditionData.current_observation.temperature_string;
var weatherCondition = conditionData.current_observation.weather;
var icon_url = conditionData.current_observation.icon_url;
var location = conditionData.current_observation.display_location.full;
res.send(body);
}
var body = {
response_type: "in_channel",
"attachments": [
{
"text": "Location: " + location + "\n"
+ "Temperature: " + temperature + "\n"
+ "Condition: " + weatherCondition,
"image_url": icon_url,
}
]
};
res.send( body );
});
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment