Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
@SpringBootApplication
@EnableFeignClients
public class TaskSchedulerApplication {

public static void main(String[] args) {
SpringApplication.run(TaskSchedulerApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class TaskService {
private final TaskUpdateConverter taskUpdateConverter;

public TaskDTO saveTask(String token, TaskDTO taskDTO) {

taskDTO.setUserEmail(jwtUtil.extractUsername(token.substring(7)));
taskDTO.setCreationDateTime(LocalDateTime.now());
taskDTO.setNotificationStatusEnum(NotificationStatusEnum.PENDING);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.javanauta.ts.taskscheduler.controller;

import com.javanauta.ts.taskscheduler.infrastructure.exception.ResourceNotFoundException;
import com.javanauta.ts.taskscheduler.infrastructure.exception.UnauthorizedException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

@ControllerAdvice
public class GlobalExceptionHandler {

@ExceptionHandler(ResourceNotFoundException.class)
public ResponseEntity<String> handlerResourceNotFoundException(ResourceNotFoundException ex) {
return new ResponseEntity<>(ex.getMessage(), HttpStatus.NOT_FOUND);
}

@ExceptionHandler(UnauthorizedException.class)
public ResponseEntity<String> handlerUnauthorizedException(UnauthorizedException ex) {
return new ResponseEntity<>(ex.getMessage(), HttpStatus.UNAUTHORIZED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.javanauta.ts.taskscheduler.infrastructure.exception;

import org.springframework.security.core.AuthenticationException;

public class UnauthorizedException extends AuthenticationException {
public UnauthorizedException(String message) {
super(message);
}

public UnauthorizedException(String message, Throwable throwable) {
super(message, throwable);
}
}