Spaces:
Building
Building
Update flare-ui/src/app/components/apis/apis.component.ts
Browse files
flare-ui/src/app/components/apis/apis.component.ts
CHANGED
@@ -552,7 +552,7 @@ export class ApisComponent implements OnInit, OnDestroy {
|
|
552 |
});
|
553 |
}
|
554 |
|
555 |
-
importAPIs() {
|
556 |
const input = document.createElement('input');
|
557 |
input.type = 'file';
|
558 |
input.accept = '.json';
|
@@ -587,7 +587,7 @@ export class ApisComponent implements OnInit, OnDestroy {
|
|
587 |
let imported = 0;
|
588 |
let failed = 0;
|
589 |
const errors: string[] = [];
|
590 |
-
|
591 |
console.log('Starting API import, total APIs:', apis.length);
|
592 |
|
593 |
for (const api of apis) {
|
@@ -597,13 +597,20 @@ export class ApisComponent implements OnInit, OnDestroy {
|
|
597 |
} catch (err: any) {
|
598 |
failed++;
|
599 |
const apiName = api.name || 'unnamed';
|
600 |
-
|
601 |
console.error(`❌ Failed to import API ${apiName}:`, err);
|
602 |
|
603 |
-
// Parse error message
|
604 |
let errorMsg = 'Unknown error';
|
|
|
605 |
if (err.status === 409) {
|
|
|
|
|
|
|
|
|
606 |
errorMsg = `API with name '${apiName}' already exists`;
|
|
|
|
|
607 |
} else if (err.error?.detail) {
|
608 |
errorMsg = err.error.detail;
|
609 |
} else if (err.message) {
|
@@ -620,22 +627,6 @@ export class ApisComponent implements OnInit, OnDestroy {
|
|
620 |
this.loadAPIs();
|
621 |
}
|
622 |
|
623 |
-
// Build detailed message
|
624 |
-
let message = '';
|
625 |
-
if (imported > 0) {
|
626 |
-
message = `Successfully imported ${imported} API${imported > 1 ? 's' : ''}.`;
|
627 |
-
}
|
628 |
-
|
629 |
-
if (failed > 0) {
|
630 |
-
if (message) message += '\n\n';
|
631 |
-
message += `Failed to import ${failed} API${failed > 1 ? 's' : ''}:`;
|
632 |
-
|
633 |
-
// Show all errors
|
634 |
-
errors.forEach(error => {
|
635 |
-
message += '\n• ' + error;
|
636 |
-
});
|
637 |
-
}
|
638 |
-
|
639 |
// Always show dialog for import results
|
640 |
try {
|
641 |
await this.showImportResultsDialog(imported, failed, errors);
|
@@ -644,7 +635,7 @@ export class ApisComponent implements OnInit, OnDestroy {
|
|
644 |
// Fallback to snackbar
|
645 |
this.showImportResultsSnackbar(imported, failed, errors);
|
646 |
}
|
647 |
-
|
648 |
} catch (error) {
|
649 |
this.loading = false;
|
650 |
this.snackBar.open('Failed to read file', 'Close', {
|
|
|
552 |
});
|
553 |
}
|
554 |
|
555 |
+
async importAPIs() {
|
556 |
const input = document.createElement('input');
|
557 |
input.type = 'file';
|
558 |
input.accept = '.json';
|
|
|
587 |
let imported = 0;
|
588 |
let failed = 0;
|
589 |
const errors: string[] = [];
|
590 |
+
|
591 |
console.log('Starting API import, total APIs:', apis.length);
|
592 |
|
593 |
for (const api of apis) {
|
|
|
597 |
} catch (err: any) {
|
598 |
failed++;
|
599 |
const apiName = api.name || 'unnamed';
|
600 |
+
|
601 |
console.error(`❌ Failed to import API ${apiName}:`, err);
|
602 |
|
603 |
+
// Parse error message - daha iyi hata mesajı parse etme
|
604 |
let errorMsg = 'Unknown error';
|
605 |
+
|
606 |
if (err.status === 409) {
|
607 |
+
// DuplicateResourceError durumu
|
608 |
+
errorMsg = `API with name '${apiName}' already exists`;
|
609 |
+
} else if (err.status === 500 && err.error?.detail?.includes('already exists')) {
|
610 |
+
// Backend'den gelen duplicate hatası
|
611 |
errorMsg = `API with name '${apiName}' already exists`;
|
612 |
+
} else if (err.error?.message) {
|
613 |
+
errorMsg = err.error.message;
|
614 |
} else if (err.error?.detail) {
|
615 |
errorMsg = err.error.detail;
|
616 |
} else if (err.message) {
|
|
|
627 |
this.loadAPIs();
|
628 |
}
|
629 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
630 |
// Always show dialog for import results
|
631 |
try {
|
632 |
await this.showImportResultsDialog(imported, failed, errors);
|
|
|
635 |
// Fallback to snackbar
|
636 |
this.showImportResultsSnackbar(imported, failed, errors);
|
637 |
}
|
638 |
+
|
639 |
} catch (error) {
|
640 |
this.loading = false;
|
641 |
this.snackBar.open('Failed to read file', 'Close', {
|