From c5280144de096c274f185fade287ccd63b954ceb Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Sun, 8 Nov 2020 21:26:34 -0500 Subject: fixed up product models and api calls, working on new product form --- iridescence/src/api/dichroism.js | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) (limited to 'iridescence/src/api') 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()); } } } -- cgit v1.2.3