async function playgroundEval(groups, groupName) {
  // Get fetch options
  const opts = createDataRequestOpts(groups, groupName)

  // Make request
  let resp
  try {
    resp = await fetch(`${PLAYGROUND}/v1/data`, opts)
  } catch (e) {
    throw new ChainedError("can't contact server", e)
  }

  // Parse response and return
  let parsed
  try {
    parsed = await resp.json()
  } catch (e) {
    throw new ChainedError('invalid response from server', e)
  }

  if (resp.status === 200) {
    if (parsed.pretty) {
      return parsed.pretty.replace(/\n$/, '') // Some responses may have trailing newlines
    }
    if (parsed.result === null) {
      throw new OPAErrors("undefined decision", undefined)
    }
    // Else throw below
  } else if (parsed.message) { // The server returned a non-200 code and a message
    const message = parsed.message.replace(/\n$/, '') // Some messages may have trailing newlines
    if (parsed.error || message === 'undefined decision') { // The error was related to evaluation
      let opaErrors
      try { // Try validating the errors by creating an OPAErrors object to throw
        opaErrors = new OPAErrors(message, parsed.error)
      } catch (e) {
        throw new ChainedError(message, e) // Errors seem to be invalid but use the message it sent anyway, it's more informative than anything else.
      }
      throw opaErrors
    } else {
      throw new Error(message)
    }
  }

  // None of the return or throw cases matched, that's unexpected
  throw new Error('invalid response from server')
}
// Evaluate the group using the playground. Either returns a string suitable for a code block or throws an error whose message is user-friendly. If the OPA evaluation itself failed, throws an OPAErrors instance.
Evaluate the group using the playground. Either returns a string suitable for a code block or throws an error whose message is user-friendly. If the OPA evaluation itself failed, throws an OPAErrors instance.
Evaluate the group using the playground . Either returns a string suitable for a code block or throws an error whose message is user - friendly . If the OPA evaluation itself failed throws an OPAErrors instance .
async function playgroundEval(groups, groupName) {
  const opts = createDataRequestOpts(groups, groupName)
  let resp
  try {
    resp = await fetch(`${PLAYGROUND}/v1/data`, opts)
  } catch (e) {
    throw new ChainedError("can't contact server", e)
  }
  let parsed
  try {
    parsed = await resp.json()
  } catch (e) {
    throw new ChainedError('invalid response from server', e)
  }
  if (resp.status === 200) {
    if (parsed.pretty) {
      return parsed.pretty.replace(/\n$/, '') 
    }
    if (parsed.result === null) {
      throw new OPAErrors("undefined decision", undefined)
    }
  } else if (parsed.message) { 
    const message = parsed.message.replace(/\n$/, '') 
    if (parsed.error || message === 'undefined decision') { 
      let opaErrors
      try { 
        opaErrors = new OPAErrors(message, parsed.error)
      } catch (e) {
        throw new ChainedError(message, e) 
      }
      throw opaErrors
    } else {
      throw new Error(message)
    }
  }
  throw new Error('invalid response from server')
}
async function playgroundEval ( groups , groupName ) { const opts = createDataRequestOpts ( groups , groupName ) let resp try { resp = await fetch ( ` ${ PLAYGROUND } ` , opts ) } catch ( e ) { throw new ChainedError ( "can't contact server" , e ) } let parsed try { parsed = await resp . json ( ) } catch ( e ) { throw new ChainedError ( 'invalid response from server' , e ) } if ( resp . status === 200 ) { if ( parsed . pretty ) { return parsed . pretty . replace ( / \n$ / , '' ) } if ( parsed . result === null ) { throw new OPAErrors ( "undefined decision" , undefined ) } } else if ( parsed . message ) { const message = parsed . message . replace ( / \n$ / , '' ) if ( parsed . error || message === 'undefined decision' ) { let opaErrors try { opaErrors = new OPAErrors ( message , parsed . error ) } catch ( e ) { throw new ChainedError ( message , e ) } throw opaErrors } else { throw new Error ( message ) } } throw new Error ( 'invalid response from server' ) }
Evaluate the group using the playground.
Evaluate the group using the playground .
// Get fetch options // Make request // Parse response and return // Some responses may have trailing newlines // Else throw below // The server returned a non-200 code and a message // Some messages may have trailing newlines // The error was related to evaluation // Try validating the errors by creating an OPAErrors object to throw // Errors seem to be invalid but use the message it sent anyway, it's more informative than anything else. // None of the return or throw cases matched, that's unexpected