Commit 60732c3c authored by Heber Cordova's avatar Heber Cordova

feat: added exception handler

parent a0dd0f9b
FROM openjdk:latest
WORKDIR /app
COPY target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java","-jar","app.jar"]
\ No newline at end of file
package com.hcordova.flightagencyapi.shared.config;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import com.hcordova.flightagencyapi.shared.dto.ErrorMessage;
import com.hcordova.flightagencyapi.shared.exceptions.NotFoundException;
@ControllerAdvice
public class ExceptionController {
@ExceptionHandler(NotFoundException.class)
public ResponseEntity<ErrorMessage> notFoundException(NotFoundException ex) {
ErrorMessage errorMessage = new ErrorMessage(ex.getMessage(), HttpStatus.NOT_FOUND, ex.getPath());
return new ResponseEntity<>(errorMessage, HttpStatus.NOT_FOUND);
}
}
package com.hcordova.flightagencyapi.shared.dto;
import org.springframework.http.HttpStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
@AllArgsConstructor
@Getter
@Setter
public class ErrorMessage {
private String message;
private HttpStatus code;
private String path;
}
package com.hcordova.flightagencyapi.shared.exceptions;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(HttpStatus.NOT_FOUND)
public class NotFoundException extends RuntimeException {
private String path;
public NotFoundException(String message) {
super(message);
this.path = this.getLocalizedMessage();
}
public String getPath() {
return path;
}
}
{"properties": [
{
"name": "db.host",
"type": "java.lang.String",
"description": "A description for 'db.host'"
},
{
"name": "app.port",
"type": "java.lang.String",
"description": "A description for 'app.port'"
}
]}
\ No newline at end of file
# METADATA
db.host=my-flight-app-network
app.port=8080
# SERVER
server.port=${app.port}:8085}
# MYSQL
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://${db.host}:localhost}:3306/flightdatabase?useSSL=false&createDatabaseIfNotExists=true
spring.datasource.username=root
spring.datasource.password=admin
# JPA
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect
spring.jpa.show-sql=true
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment