const REGEXP = /((?:[a-zA-Z0-9._~+/-]+=*(?:\s+|$))|[^()<>@,;:\\"/?={}[\] ]+)(?:=([^\\"=\s,]+|"(?:[^"\\]|\\.)*"))?/g;
const NOPE = [false];

module.exports = function isBearerHeaderOnlyError(error) {
  if (error instanceof this.httpClient.HTTPError) {
    try {
      const body = {};
      if (!error.response.headers['www-authenticate'].startsWith('Bearer ')) {
        return NOPE;
      }

      while ((REGEXP.exec(error.response.headers['www-authenticate'])) !== null) {
        if (RegExp.$1 && RegExp.$2) {
          body[RegExp.$1] = RegExp.$2.slice(1, -1);
        }
      }

      return [!!body.error, body];
    } catch (err) {}
  }

  return NOPE;
};

@@ -14,104 +14,22 @@
 = /(
-(?:%5Ba-zA-Z0-9._~+/-%5D+=*(?:%5Cs+%7C$))%7C%5B%5E()%3C%3E@,;:%5C%5C%22/?=%7B%7D%5B%5C%5D %5D+)(?:=(%5B%5E%5C%5C%22=%5Cs,%5D+%7C%22(?:%5B%5E%22%5C%5C%5D%7C%5C%5C.)
+%5Cw+)=(%22%5B%5E%22%5D
 *%22)
-)?
 /g;%0A

apply safer, simpler www-authenticate parsing regex