Co-authored-by: Mikhail Bashkirov <mikhail.bashkirov@ing.com> Co-authored-by: Thijs Louisse <thijs.louisse@ing.com> Co-authored-by: Joren Broekema <joren.broekema@ing.com> Co-authored-by: Gerjan van Geest <gerjan.van.geest@ing.com> Co-authored-by: Erik Kroes <erik.kroes@ing.com> Co-authored-by: Lars den Bakker <lars.den.bakker@ing.com>
16 lines
414 B
JavaScript
16 lines
414 B
JavaScript
export function jsonPrefixTransformerFactory(prefix) {
|
|
return data => {
|
|
let result = data;
|
|
if (typeof result === 'string') {
|
|
if (prefix.length > 0 && result.indexOf(prefix) === 0) {
|
|
result = result.substring(prefix.length);
|
|
}
|
|
try {
|
|
result = JSON.parse(result);
|
|
} catch (e) {
|
|
/* ignore to allow non-JSON responses */
|
|
}
|
|
}
|
|
return result;
|
|
};
|
|
}
|