Skip to content

Commit d2308bd

Browse files
authored
Merge pull request #3 from Zenfulcode/fix-load-currency-error
fix(currency): Improve error handling for currency and category fetching in product form
2 parents c1d5e70 + 7bcfb09 commit d2308bd

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

Makefile

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@ help: ## Show this help message
55
@echo "Available commands:"
66
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
77

8-
9-
# Docker image commands
10-
docker-build: ## Build Docker image
11-
docker build -t ghcr.io/zenfulcode/commercify-app:latest .
12-
138
docker-build-tag: ## Build Docker image with specific tag (use TAG=version)
149
@if [ -z "$(TAG)" ]; then echo "Error: TAG is required. Use: make docker-build-tag TAG=v1.0.0"; exit 1; fi
15-
docker build -t ghcr.io/zenfulcode/commercify-app:$(TAG) -t ghcr.io/zenfulcode/commercify-app:latest -t ghcr.io/zenfulcode/commercify-app:dev .
10+
docker build -t ghcr.io/zenfulcode/commercify-app:$(TAG) -t ghcr.io/zenfulcode/commercify-app:dev .
1611

1712
docker-push: ## Push Docker image to registry (use REGISTRY and TAG)
1813
@if [ -z "$(REGISTRY)" ]; then echo "Error: REGISTRY is required. Use: make docker-push REGISTRY=your-registry.com"; exit 1; fi
1914
@if [ -z "$(TAG)" ]; then echo "Error: TAG is required. Use: make docker-push REGISTRY=your-registry.com TAG=v1.0.0"; exit 1; fi
2015
docker push $(REGISTRY)/commercify-app:$(TAG)
21-
docker push $(REGISTRY)/commercify-app:latest
2216
docker push $(REGISTRY)/commercify-app:dev
2317

2418
docker-build-push: docker-build-tag docker-push ## Build and push Docker image (use REGISTRY and TAG)

src/lib/mappers/currency.mapper.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ export const currenyListMapper = (
1616
};
1717
}
1818

19-
console.log('Currency list fetched successfully:', dto.data);
20-
2119
return {
2220
data: dto.data.map(currencyMapper),
2321
success: dto.success,

src/routes/admin/products/new/+page.server.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@ export const load: PageServerLoad = async ({ locals }) => {
1313
const form = await superValidate(zod(productSchema));
1414

1515
// Get available currencies for the form
16-
const [currencies, categories] = await Promise.all([
16+
const [currenciesResult, categoriesResult] = await Promise.allSettled([
1717
commercify.currencies.list(),
1818
commercify.categories.list()
1919
]);
20+
21+
if (currenciesResult.status === 'rejected' || categoriesResult.status === 'rejected') {
22+
console.error('Failed to fetch currencies or categories');
23+
return fail(500, {
24+
form,
25+
message: 'Failed to load currencies or categories. Please try again later.'
26+
});
27+
}
28+
29+
const currencies = currenciesResult.value;
30+
const categories = categoriesResult.value;
31+
2032
if (!currencies || !categories) {
2133
console.error('Failed to fetch currencies or categories');
2234
return fail(500, {
@@ -41,13 +53,11 @@ export const load: PageServerLoad = async ({ locals }) => {
4153
});
4254
}
4355

44-
form.data.currency = currencies.data!.items.find(
45-
(currency: Currency) => currency.isDefault
46-
)!.code;
56+
form.data.currency = currencies.data.find((currency: Currency) => currency.isDefault)!.code;
4757

4858
return {
4959
form,
50-
currencies: currencies.success ? currencies.data?.items : [],
60+
currencies: currencies.success ? currencies.data : [],
5161
categories: categories.success ? categories.data : []
5262
};
5363
} catch (error) {

0 commit comments

Comments
 (0)