AngularJS defaultHttpResponseTransform
tries to figure out if data is json and tries to parse it:
function defaultHttpResponseTransform(data, headers) {
if (isString(data)) {
// Strip json vulnerability protection prefix and trim whitespace
var tempData = data.replace(JSON_PROTECTION_PREFIX, '').trim();
if (tempData) {
var contentType = headers('Content-Type');
if ((contentType && (contentType.indexOf(APPLICATION_JSON) === 0)) || isJsonLike(tempData)) {
data = fromJson(tempData);
}
}
}
return data;
}
However data in response in text/plain
that is swift
message, and looks like JSON
but it is not. And when Angular tries to JSON.parse
it, I get error:
SyntaxError: Unexpected number at Object.parse (native) at fromJson (http://localhost:8080/WebEastGui/build/js/app-vendor.js:41198:14)
Is there a way to force Angular not to force parsing JSON like string?
Read about Overriding the Default Transformations Per Request
from $http docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With