diff options
author | Adam T. Carpenter <atc@53hor.net> | 2020-11-08 21:26:34 -0500 |
---|---|---|
committer | Adam T. Carpenter <atc@53hor.net> | 2020-11-08 21:26:34 -0500 |
commit | c5280144de096c274f185fade287ccd63b954ceb (patch) | |
tree | 169f1c2ad86c68e5ccb37494398c5e2db33dca3d /iridescence/src/api | |
parent | 7dd36c0e699a1154c7163f25bf488fbd63edeafe (diff) | |
download | theglassyladies-c5280144de096c274f185fade287ccd63b954ceb.tar.xz theglassyladies-c5280144de096c274f185fade287ccd63b954ceb.zip |
fixed up product models and api calls, working on new product form
Diffstat (limited to 'iridescence/src/api')
-rw-r--r-- | iridescence/src/api/dichroism.js | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/iridescence/src/api/dichroism.js b/iridescence/src/api/dichroism.js index e3b08a8..610941c 100644 --- a/iridescence/src/api/dichroism.js +++ b/iridescence/src/api/dichroism.js @@ -14,13 +14,23 @@ export default class Dichroism { body: fd }; - const photos = await self._sendRequest("photos", options); - return photos.map(p => new PhotoSet(p)); + try { + const photos = await this._sendRequest("photos", options); + return photos.map(p => new PhotoSet(p)); + } catch (err) { + console.error(err.message); + return null; + } } async getProducts() { - const products = await self._sendRequest("products", null); - return products.map(p => new Product(p)); + try { + const products = await this._sendRequest("products", null); + return products.map(p => new Product(p)); + } catch (err) { + console.error(err.message); + return []; + } } async updateProduct(fieldDiff) { @@ -29,8 +39,13 @@ export default class Dichroism { body: fieldDiff }; - const product = await self._sendRequest("products", options); - return new Product(product); + try { + const product = await this._sendRequest("products", options); + return new Product(product); + } catch (err) { + console.error(err.message); + return null; + } } async createProduct(newProduct) { @@ -39,17 +54,22 @@ export default class Dichroism { body: newProduct }; - const product = await self._sendRequest("products", options); - return new Product(product); + try { + const product = await this._sendRequest("products", options); + return new Product(product); + } catch (err) { + console.error(err.message); + return null; + } } async _sendRequest(endpoint, options) { - const response = await fetch(self.base_addr + endpoint, options); + const response = await fetch(this._base_addr + endpoint, options); if (response.ok) { return await response.json(); } else { - return new ApiError(await response.text()); + throw new ApiError(await response.text()); } } } |