wadl-client
Advanced tools
Comparing version 0.1.6 to 0.1.7
{ | ||
"name": "wadl-client", | ||
"main": "wadl-client.js", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"homepage": "https://github.com/rbelouin/wadl-client", | ||
@@ -6,0 +6,0 @@ "authors": [ |
{ | ||
"name": "wadl-client", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Generate a Javascript client for a web API providing a WADL description", | ||
@@ -5,0 +5,0 @@ "main": "wadl-client.js", |
@@ -53,2 +53,7 @@ var resources = { | ||
}], | ||
"/test/json4": [{ | ||
"verb": "GET", | ||
"name": "getJSONData4", | ||
"params": [] | ||
}], | ||
"/test/xml": [{ | ||
@@ -63,3 +68,8 @@ "verb": "GET", | ||
"params": [] | ||
}] | ||
}], | ||
"/test/json/fail2": [{ | ||
"verb": "GET", | ||
"name": "getJSONFailData2", | ||
"params": [] | ||
}], | ||
}; | ||
@@ -66,0 +76,0 @@ |
@@ -57,2 +57,7 @@ var http = require("http"); | ||
app.get("/test/json4", function(req, res){ | ||
res.setHeader("Content-Type", "application/json"); | ||
res.send("{'a':'1', 'b'"); | ||
}); | ||
app.get("/test/xml", function(req, res) { | ||
@@ -72,2 +77,8 @@ res.setHeader("Content-Type", "application/atom+xml"); | ||
app.get("/test/json/fail2", function(req, res){ | ||
res.statusCode = 400; | ||
res.setHeader("Content-Type", "application/json"); | ||
res.send("{'a':'1', 'b'"); | ||
}); | ||
var server; | ||
@@ -74,0 +85,0 @@ |
@@ -231,2 +231,28 @@ var resources = resources || require("./resources.js"); | ||
}); | ||
it("must not throw TypeError if resource is not JSON even if Content-Type header says so", function(done){ | ||
var client = WadlClient.buildClient(resources, { | ||
host: 'http://localhost:3000', | ||
parseJSON: true | ||
}); | ||
var p = client.test.json4.get()(); | ||
p.mapError(function(error){ | ||
done(); | ||
}); | ||
}); | ||
it("must not throw TypeError if resource is not JSON even if Content-Type header says so and status is not 200", function(done){ | ||
var client = WadlClient.buildClient(resources, { | ||
host: 'http://localhost:3000', | ||
parseJSON: true | ||
}); | ||
var p = client.test.json.fail2.get()(); | ||
p.mapError(function(error){ | ||
done(); | ||
}); | ||
}); | ||
}); |
@@ -74,3 +74,7 @@ var WadlClient = (function() { | ||
if(options.parseJSON && nodeResponseHeaderHasValue(response, "content-type", ["application/json"])) { | ||
result.resolve(JSON.parse(body)); | ||
try{ | ||
result.resolve(JSON.parse(body)); | ||
} catch(e){ | ||
result.reject(e); | ||
} | ||
} | ||
@@ -89,3 +93,7 @@ else if(options.parseXML && nodeResponseHeaderHasValue(response, "content-type", ["text/xml", "application/rss+xml", "application/rss+xml", "application/atom+xml"])) { | ||
if(options.parseJSON && nodeResponseHeaderHasValue(response, "content-type", ["application/json"])) { | ||
result.reject(JSON.parse(body)); | ||
try{ | ||
result.reject(JSON.parse(body)); | ||
} catch(e){ | ||
result.reject(e); | ||
} | ||
} | ||
@@ -119,3 +127,7 @@ else if(options.parseXML && nodeResponseHeaderHasValue(response, "content-type", ["text/xml", "application/rss+xml", "application/rss+xml", "application/atom+xml"])) { | ||
if(options.parseJSON && browserResponseHeaderHasValue(xhr, "Content-Type", ["application/json"])) { | ||
result.resolve(JSON.parse(xhr.responseText)); | ||
try{ | ||
result.resolve(JSON.parse(xhr.responseText)); | ||
} catch(e){ | ||
result.reject(e); | ||
} | ||
} | ||
@@ -131,3 +143,7 @@ else if(options.parseXML && browserResponseHeaderHasValue(xhr, "Content-Type", ["text/xml", "application/rss+xml", "application/rss+xml", "application/atom+xml"])) { | ||
if(options.parseJSON && browserResponseHeaderHasValue(xhr, "Content-Type", ["application/json"])) { | ||
result.reject(JSON.parse(xhr.responseText)); | ||
try{ | ||
result.reject(JSON.parse(xhr.responseText)); | ||
} catch(e){ | ||
result.reject(e); | ||
} | ||
} | ||
@@ -134,0 +150,0 @@ else if(options.parseXML && browserResponseHeaderHasValue(xhr, "Content-Type", ["text/xml", "application/rss+xml", "application/rss+xml", "application/atom+xml"])) { |
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
22248
652