Skip to content

Commit 5fb89b2

Browse files
fix: zip validation order (googlemaps#238)
1 parent e546562 commit 5fb89b2

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

application/frontend/src/app/core/containers/upload-dialog/upload-dialog.component.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,12 @@ export class UploadDialogComponent {
163163
return;
164164
}
165165

166+
this.fileInvalid = false;
167+
this.zipContentsInvalid = false;
168+
this.zipContentCountInvalid = false;
169+
this.zipMissingScenario = false;
170+
this.zipMissingSolution = false;
171+
166172
this.selectedFilename = file.name.replace(/\.[^/.]+$/, '');
167173

168174
this.validatingUpload = true;
@@ -331,11 +337,11 @@ export class UploadDialogComponent {
331337
let solution;
332338
files.forEach((file) => {
333339
if (!scenario || !Object.keys(scenario).length) {
334-
scenario = this.validateScenario(file.content);
340+
scenario = this.validateScenario(file.content).scenario;
335341
}
336342

337343
if (!solution || !Object.keys(solution).length) {
338-
solution = this.validateSolution(file.content);
344+
solution = this.validateSolution(file.content).solution;
339345
}
340346
});
341347

@@ -374,35 +380,32 @@ export class UploadDialogComponent {
374380
* Only validates the message/value structure
375381
*/
376382
scenarioValidator(_: UntypedFormControl): ValidationErrors | null {
377-
try {
378-
const scenario = this.validateScenario(this.json);
379-
380-
if (this.scenario == null) {
381-
this.scenario = scenario;
382-
}
383-
} catch (error) {
383+
const res = this.validateScenario(this.json);
384+
if (this.scenario == null && res.isValid) {
385+
this.scenario = res.scenario;
386+
return null;
387+
} else {
384388
// eslint-disable-next-line no-console
385-
console.log('Invalid request format:', error);
389+
console.error(res.validationResult);
386390
return { requestFormat: true };
387391
}
388-
return null;
389392
}
390393

391-
validateScenario(json: any): Scenario {
394+
validateScenario(json: any): { scenario: Scenario; isValid: boolean; validationResult?: any } {
392395
const validationResult = this.uploadService.validateScenarioFormat(json);
393396
if (validationResult) {
394-
throw validationResult;
397+
return { scenario: null, isValid: false, validationResult };
395398
}
396399

397-
return this.dispatcherService.objectToScenario(json);
400+
return { scenario: this.dispatcherService.objectToScenario(json), isValid: true };
398401
}
399402

400-
validateSolution(json: any): Solution {
403+
validateSolution(json: any): { solution: Solution; isValid: boolean; validationResult?: any } {
401404
const validationResult = this.uploadService.validateSolutionFormat(json);
402405
if (validationResult) {
403-
throw validationResult;
406+
return { solution: null, isValid: false, validationResult };
404407
}
405408

406-
return this.dispatcherService.objectToSolution(json);
409+
return { solution: this.dispatcherService.objectToSolution(json), isValid: true };
407410
}
408411
}

0 commit comments

Comments
 (0)