Skip to content

Commit

Permalink
Merge pull request #491 from MauroDataMapper/feature/gh-441_data_spec…
Browse files Browse the repository at this point in the history
…_report_error

gh-441: Provide more useful error message when there is a data specif…
  • Loading branch information
NigelPalmer authored Dec 13, 2024
2 parents fb0cc2a + 7922a54 commit 0cefb0f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/app/data-explorer/data-specification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,13 @@ export class DataSpecificationService {
of(dataElements),
]);
}),
catchError((error) => {
catchError((error: HttpErrorResponse) => {
const errorMessage = this.isDataSpecificationNameClashError(error)
? 'A data specification with this name already exists. Please choose a different name.'
: error.message;

this.toastr.error(
`There was a problem creating your data specification. ${error}`,
`There was a problem creating your data specification. ${errorMessage}`,
'Data specification creation error'
);
return EMPTY;
Expand Down Expand Up @@ -863,4 +867,14 @@ export class DataSpecificationService {
})
);
}

private isDataSpecificationNameClashError(error: HttpErrorResponse) {
if (error.status === 422 && error.error && Array.isArray(error.error.errors)) {
// Extract the first error message
return error.error.errors.some((err: { message: string }) =>
err.message?.includes('must be unique by branch name')
);
}
return false;
}
}

0 comments on commit 0cefb0f

Please sign in to comment.