diff options
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()); } } } |