allow parsing of response body even if status was unauthorized (client-specific work...
[squeep-indieauth-helper] / lib / communication.js
index 0116548d6539eb70fe229df71aee35cf86305034..8f6110f6e3a9c3438a0855ead9af3db3eb59b0e9 100644 (file)
@@ -124,6 +124,17 @@ class Communication {
   }
 
 
+  /**
+   * Valid response statuses.
+   * Allow 401 as a workaround for one specific client which return such on
+   * its client identifier endpoint when not yet authenticated.
+   * @param {Number} status
+   * @returns {Boolean}
+   */
+  static _validateStatus(status) {
+    return (status >= 200 && status < 300) || status == 401;
+  }
+
   /**
    * A request config skeleton.
    * @param {String} method
@@ -144,6 +155,8 @@ class Communication {
       responseType: 'text',
       // So force the matter by eliding all response transformations
       transformResponse: [ (res) => res ],
+
+      validateStatus: Communication._validateStatus,
     };
     Object.entries(params).map(([k, v]) => config.params.set(k, v));
     return config;