Spaces:
Paused
Paused
Update flare-ui/src/app/dialogs/api-edit-dialog/api-edit-dialog.component.ts
Browse files
flare-ui/src/app/dialogs/api-edit-dialog/api-edit-dialog.component.ts
CHANGED
|
@@ -331,7 +331,7 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
| 331 |
|
| 332 |
return processed;
|
| 333 |
}
|
| 334 |
-
|
| 335 |
async testAPI() {
|
| 336 |
// Validate form first
|
| 337 |
const generalValid = this.form.get('url')?.valid && this.form.get('method')?.valid;
|
|
@@ -339,24 +339,40 @@ export default class ApiEditDialogComponent implements OnInit {
|
|
| 339 |
this.snackBar.open('Please fill in required fields first', 'Close', { duration: 3000 });
|
| 340 |
return;
|
| 341 |
}
|
| 342 |
-
|
| 343 |
this.testing = true;
|
| 344 |
this.testResult = null;
|
| 345 |
-
|
| 346 |
try {
|
| 347 |
const testData = this.prepareAPIData();
|
| 348 |
|
| 349 |
-
//
|
| 350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
testData.test_request = testRequestData;
|
| 352 |
|
| 353 |
const result = await this.apiService.testAPI(testData).toPromise();
|
| 354 |
this.testResult = result;
|
| 355 |
-
|
|
|
|
| 356 |
if (result.success) {
|
| 357 |
-
this.snackBar.open(
|
|
|
|
|
|
|
| 358 |
} else {
|
| 359 |
-
|
|
|
|
| 360 |
duration: 5000,
|
| 361 |
panelClass: 'error-snackbar'
|
| 362 |
});
|
|
|
|
| 331 |
|
| 332 |
return processed;
|
| 333 |
}
|
| 334 |
+
|
| 335 |
async testAPI() {
|
| 336 |
// Validate form first
|
| 337 |
const generalValid = this.form.get('url')?.valid && this.form.get('method')?.valid;
|
|
|
|
| 339 |
this.snackBar.open('Please fill in required fields first', 'Close', { duration: 3000 });
|
| 340 |
return;
|
| 341 |
}
|
| 342 |
+
|
| 343 |
this.testing = true;
|
| 344 |
this.testResult = null;
|
| 345 |
+
|
| 346 |
try {
|
| 347 |
const testData = this.prepareAPIData();
|
| 348 |
|
| 349 |
+
// Parse test request JSON
|
| 350 |
+
let testRequestData = {};
|
| 351 |
+
try {
|
| 352 |
+
testRequestData = JSON.parse(this.testRequestJson);
|
| 353 |
+
} catch (e) {
|
| 354 |
+
this.snackBar.open('Invalid test request JSON', 'Close', {
|
| 355 |
+
duration: 3000,
|
| 356 |
+
panelClass: 'error-snackbar'
|
| 357 |
+
});
|
| 358 |
+
this.testing = false;
|
| 359 |
+
return;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
// Add test request to the data
|
| 363 |
testData.test_request = testRequestData;
|
| 364 |
|
| 365 |
const result = await this.apiService.testAPI(testData).toPromise();
|
| 366 |
this.testResult = result;
|
| 367 |
+
|
| 368 |
+
// Show appropriate message based on actual success
|
| 369 |
if (result.success) {
|
| 370 |
+
this.snackBar.open(`API test successful! (${result.status_code})`, 'Close', {
|
| 371 |
+
duration: 3000
|
| 372 |
+
});
|
| 373 |
} else {
|
| 374 |
+
const errorMsg = result.error || `API returned status ${result.status_code}`;
|
| 375 |
+
this.snackBar.open(`API test failed: ${errorMsg}`, 'Close', {
|
| 376 |
duration: 5000,
|
| 377 |
panelClass: 'error-snackbar'
|
| 378 |
});
|