UNPKG

ih-black-lion

Version:

State handler for Arus projects

37 lines (34 loc) 1.09 kB
/** * Checks if a response object is a `Fault` or not. * * @param {Object} resp The response object that is being checked for a `Fault`. * @return {Boolean} Returns `true` if `resp` is a `Fault`, `false` otherwise. */ function interceptFault(resp) { // Gets the response's 2nd-level node const body = resp[Object.keys(resp)[0]]; if (body.IS_FAULT && body.IS_FAULT[0] && body.IS_FAULT[0] === 'Y') { // return resp if it's a Fault return resp; } else if (body.HEAD && body.HEAD[0] && body.HEAD[0].TITLE && body.HEAD[0].TITLE[0] === 'RESTListeningConnector') { // this is also considered a Fault although it doesn't follow the same pattern as the others return resp; } // return false if resp isn't a Fault return false; } function toCamelCase(str) { const words = str.toLowerCase().split('_'); let camelCase = ''; for (let i = 0; i < words.length; i += 1) { if (i > 0) { words[i] = words[i][0].toUpperCase() + words[i].substr(1); } camelCase += words[i]; } return camelCase; } export { interceptFault, toCamelCase, };