Repository URL to install this package:
|
Version:
1.3.0 ▾
|
/* eslint-disable brace-style */
import { size } from 'chain-able-deps'
import { toNumber, isObj } from 'exotic'
import { getOneOfFor } from './_getOneOfFor'
const knownStatuses = Object.freeze([
'properties.state.status',
'responseMessage',
])
const getKnownStatus = getOneOfFor(knownStatuses)
// 'User Not Logged In'
// OF COURSE SUCCESS ON THIS IS 101001
// https://jira.skava.net/confluence/display/SKC/List+Error+Response+Code
// const API_ERROR_MAP = Object.freeze([701, 1])
/**
* @todo fix this crazy Object(...) error from imports
* wherever it happens in webpack!!!
*
* @invariant 1 status.includes(Error) == Error
* @invariant 2 Object.keys(response).length < 3 == Error
*
* @param {*} response
* @return {boolean | Error}
*/
function isErrorLikeStatus(status) {
if (status.includes('success')) {
// to handle status like -> 'Success - Few or All items has error'
return false
} else {
// "No internal transform type"
// @todo @James @included 'failed' in status response
return (
status.includes('transform') ||
status.includes('error') ||
status.includes('failure') ||
status.includes('failed')
)
}
}
function isErrorLikeResponse(response) {
// unify casing, get any of the known status properties
const status = getKnownStatus(response).toLowerCase()
// fromResponseToMessage
// this is what we show in an error popup
const message = isObj(response) === true ? response.responseMessage || '' : ''
// defaults to 0
const code = isObj(response) === true ? toNumber(response.responseCode) : 99
if (code !== 0 && code !== 101001) {
return true
} else if (message.includes('failure')) {
return true
} else if (message.includes('failed')) {
return true
} else if (isErrorLikeStatus(status)) {
return true
}
// search comes back with 1-2!
else if (size(response) < 2) {
return true
} else {
return false
}
}
export { isErrorLikeResponse }
export default isErrorLikeResponse