Catch undefined content-type headers
If content-type is undefined then catch the exception and set it to empty just as is done for the body.
This commit is contained in:
parent
af563db0e2
commit
13717bd4f7
@ -109,15 +109,21 @@ function fetch(url, cb) {
|
|||||||
.pipe(es.wait(function(err, data) {
|
.pipe(es.wait(function(err, data) {
|
||||||
if (err) return;
|
if (err) return;
|
||||||
var body;
|
var body;
|
||||||
|
var type;
|
||||||
try {
|
try {
|
||||||
body = JSON.parse(data);
|
body = JSON.parse(data);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
body = {};
|
body = {};
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
type = req.response.headers['content-type'].split(/ *; */).shift();
|
||||||
|
} catch(e) {
|
||||||
|
type = {};
|
||||||
|
}
|
||||||
data = {
|
data = {
|
||||||
text: data,
|
text: data,
|
||||||
body: body,
|
body: body,
|
||||||
type: req.response.headers['content-type'].split(/ *; */).shift()
|
type: type
|
||||||
};
|
};
|
||||||
cb(data);
|
cb(data);
|
||||||
}));
|
}));
|
||||||
|
Loading…
Reference in New Issue
Block a user