Comparing version 0.1.1 to 0.1.2
21
index.js
@@ -66,5 +66,7 @@ var request = require('request'); | ||
function ForecastIoError(url, statusCode, body) { | ||
Error.call(this); | ||
Error.captureStackTrace(this, arguments.callee); | ||
this.request = 'GET ' + url; | ||
// Try to parse error response's body, since it's most probably JSON | ||
try { | ||
body = JSON.parse(body) | ||
} catch(e) {} | ||
this.response = { | ||
@@ -74,2 +76,7 @@ statusCode: statusCode, | ||
}; | ||
this.message = this._formatErrorMessage(body); | ||
this.name = 'ForecastIoError'; | ||
Error.call(this); | ||
Error.captureStackTrace(this, arguments.callee); | ||
this.request = 'GET ' + url; | ||
} | ||
@@ -79,3 +86,4 @@ util.inherits(ForecastIoError, Error); | ||
ForecastIoError.prototype.toString = function() { | ||
return "ForecastIoError: " + JSON.stringify({ | ||
return this.name + ": " + JSON.stringify({ | ||
message: this.mesage, | ||
request: this.request, | ||
@@ -86,3 +94,8 @@ response: this.response | ||
ForecastIoError.prototype._formatErrorMessage = function(body) { | ||
if ((body.code !== undefined) && (body.error !== undefined)) | ||
return "[" + body.code + "] " + body.error; | ||
return "Request Failed"; | ||
}; | ||
module.exports = ForecastIo; |
{ | ||
"name": "forecastio", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "A node.js wrapper for Forecast.io API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
forecastio | ||
========== | ||
[![Build Status](https://travis-ci.org/soplakanets/node-forecastio.svg?branch=master)](https://travis-ci.org/soplakanets/node-forecastio) | ||
[![Build Status](https://travis-ci.org/soplakanets/node-forecastio.svg?branch=master)](https://travis-ci.org/soplakanets/node-forecastio) [![Dependency Status](https://david-dm.org/soplakanets/node-forecastio.png)](https://david-dm.org/soplakanets/node-forecastio) | ||
@@ -21,3 +21,3 @@ A node.js client library for [Forecast.io API](https://developer.forecast.io). | ||
``` | ||
```javascript | ||
var ForecastIo = require('forecastio'); | ||
@@ -36,3 +36,3 @@ | ||
``` | ||
```javascript | ||
// What was the weather like in London on January 1st 2008? | ||
@@ -47,3 +47,3 @@ forecastIo.timeMachine('51.506', '-0.127', '2008-01-01T00:00:01Z', function(err, data) { | ||
Both `#forecast()` and `#timeMachine()` methods support passing additional options. | ||
*Below are some example, for all options consult [Forecast.IO API documentation](https://developer.forecast.io/docs/v2).* | ||
*Below are some examples, for all options consult [Forecast.IO API documentation](https://developer.forecast.io/docs/v2).* | ||
@@ -53,3 +53,3 @@ | ||
``` | ||
```javascript | ||
var options = { | ||
@@ -65,5 +65,5 @@ units: 'si', | ||
"Time Machine" request in Si units and localized in Italian: | ||
Another example, a "Time Machine" request in Si units and localized in Italian: | ||
``` | ||
```javascript | ||
var options = { | ||
@@ -92,1 +92,7 @@ units: 'si', | ||
* Create a pull request | ||
## Changelog | ||
#### 0.1.2 | ||
- More informative error messages. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10052
161
93