Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules-modules / src / isErrorLikeResponse / isErrorLikeResponse.ts
Size: Mime:
// import { isErrorLikeResponse as isErrorLikeResponseModules } from '@skava/request/deps/isErrorLikeResponse'
import { isObj, isArray } from 'exotic'
import { isErrorLikeResponse as isErrorLikeResponseModules } from './_isErrorLikeResponse'
import { getOneOf, getOneOfFor } from './_getOneOfFor'

function fromGraphqlOrAnyToResponse(x) {
  // Object.isFrozen(x) ||
  const isGraphQueryLanguage = (isObj(x) && isObj(x.data))
  if (isGraphQueryLanguage) {
    if (x.error) {
      return true
    }

    // example:
    // { data: { cart: { } } } => cart
    const found = Object.keys(x.data).pop()
    const response = x.data[found]
    return isErrorLikeResponseModules(response)
  } else {
    return isErrorLikeResponseModules(x)
  }
}

// { response: state: status }
// { data: cart: response: state: status }
// Object.keys(response).length <= 1 => with gql this is always true
// so it needs to handle that
export function isErrorLikeResponse(x) {
  return fromGraphqlOrAnyToResponse(x)
}