Skip to content

rock.get with opts.json always get false #7

@nswbmw

Description

@nswbmw
;['get', 'post', 'put', 'patch', 'head', 'delete', 'getJSON', 'postJSON', 'putJSON', 'patchJSON', 'headJSON', 'deleteJSON'].forEach(method => {
    const jsonShortcut = /JSON$/.test(method) === true
    const methodShortcut = jsonShortcut === true ? method.toUpperCase().slice(0, -4) : method.toUpperCase()
    rock[method] = (opts, body, cb) => {
      if (typeof opts === 'string') opts = { url: opts }
      opts.method = methodShortcut
      opts.json = jsonShortcut // <-- rock.get always get false
      return rock(opts, body, cb)
    }
    rock.promises[method] = (opts, body) => {
      return new Promise((resolve, reject) => {
        rock[method](opts, body, (err, response, data) => {
          if (err) return reject(err)
          resolve({ response, data })
        })
      })
    }
  })

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions