Skip to content

Commit

Permalink
bug:Refactor Exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
shijinrajbosch authored and tunacicek committed Dec 22, 2023
1 parent 543d63a commit 2b661c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 63 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## fixed
- default value for registry authentication has been corrected to 'true' in the documentation
- Refactored DuplicateKey Exception handling


## 0.3.21
### Added

## fixed
- Refactored DuplicateKeyException Exception handling

## 0.3.21
### Added

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import org.eclipse.tractusx.semantics.aas.registry.model.Message;
import org.eclipse.tractusx.semantics.aas.registry.model.Result;
import org.eclipse.tractusx.semantics.registry.model.support.DatabaseExceptionTranslation;
import org.eclipse.tractusx.semantics.registry.service.EntityNotFoundException;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -97,9 +95,9 @@ public ResponseEntity<Object> handleMethodArgumentNotSupportedException( final H

@ExceptionHandler( { DuplicateKeyException.class } )
@ResponseStatus( HttpStatus.BAD_REQUEST )
public ResponseEntity<Object> handleDuplicateKeyException( DuplicateKeyException e ) {
public ResponseEntity<Object> handleDuplicateKeyException( DuplicateKeyException duplicateKeyException ) {
return new ResponseEntity<>(
new Result().messages( List.of( new Message().messageType( Message.MessageTypeEnum.ERROR ).text( DatabaseExceptionTranslation.translate( e ) ) ) ),
new Result().messages( List.of( new Message().messageType( Message.MessageTypeEnum.ERROR ).text(duplicateKeyException.getMessage() ) ) ),
HttpStatus.BAD_REQUEST );
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import org.eclipse.tractusx.semantics.registry.model.ShellIdentifier;
import org.eclipse.tractusx.semantics.registry.model.Submodel;
import org.eclipse.tractusx.semantics.registry.model.projection.ShellMinimal;
import org.eclipse.tractusx.semantics.registry.model.support.DatabaseExceptionTranslation;
import org.eclipse.tractusx.semantics.registry.repository.ShellIdentifierRepository;
import org.eclipse.tractusx.semantics.registry.repository.ShellRepository;
import org.eclipse.tractusx.semantics.registry.repository.SubmodelRepository;
Expand Down Expand Up @@ -429,9 +428,8 @@ public List<BatchResultDto> saveBatch(List<Shell> shells) {
return new BatchResultDto("AssetAdministrationShell successfully created.",
shell.getIdExternal(), HttpStatus.OK.value());
} catch (Exception e) {
if (e.getCause() instanceof DuplicateKeyException) {
DuplicateKeyException duplicateKeyException = (DuplicateKeyException) e.getCause();
return new BatchResultDto(DatabaseExceptionTranslation.translate(duplicateKeyException),
if ( e.getCause() instanceof DuplicateKeyException duplicateKeyException ) {
return new BatchResultDto(duplicateKeyException.getMessage(),
shell.getIdExternal(),
HttpStatus.BAD_REQUEST.value());
}
Expand Down

0 comments on commit 2b661c8

Please sign in to comment.