Skip to content
Open
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 @@ -5,6 +5,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
Expand All @@ -14,6 +16,9 @@
import br.com.viktor.javawebpoc.exception.alreadyExists.AlreadyExistsException;
import br.com.viktor.javawebpoc.exception.invalidArgument.InvalidArgumentException;
import br.com.viktor.javawebpoc.exception.notFound.NotFoundException;
import br.com.viktor.javawebpoc.l10n.MessageKey;

import com.fasterxml.jackson.core.JsonParseException;

@ControllerAdvice
public class GlobalExceptionHandler {
Expand Down Expand Up @@ -53,4 +58,25 @@ public ErrorResponse generalExceptionHandler(JavaWebPoCException ex, Locale loca
return response;
}

@ExceptionHandler(HttpRequestMethodNotSupportedException.class)
@ResponseStatus(value = HttpStatus.NOT_IMPLEMENTED)
@ResponseBody
public ErrorResponse jsonErrorHandler(HttpRequestMethodNotSupportedException ex, Locale locale){
ErrorResponse response = new ErrorResponse();
response.setMessage(messageSource.getMessage(MessageKey.METHODNOTSUPPORTED_EXCEPTION.getMessageKey(), new Object[]{}, locale));
return response;
}

@ExceptionHandler(HttpMessageNotReadableException.class)
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
public ErrorResponse httpMessageInvalidErrorHandler(HttpMessageNotReadableException ex, Locale locale){
if(ex.getCause() instanceof JsonParseException){
ErrorResponse response = new ErrorResponse();
response.setMessage(messageSource.getMessage(MessageKey.JSONBADREQUEST_EXCEPTION.getMessageKey(), new Object[]{}, locale));
return response;
}
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public enum MessageKey {
NULLARGUMENT_EXCEPTION("br.com.viktor.javawebpoc.exception.nullargumentexception"),
INVALIDSTUDENT_EXCEPTION("br.com.viktor.javawebpoc.exception.invalidstudentexception"),
NOTFOUND_EXCEPTION("br.com.viktor.javawebpoc.exception.notfoundexception"),
JSONBADREQUEST_EXCEPTION("br.com.viktor.javawebpoc.exception.jsonbadrequest"),
METHODNOTSUPPORTED_EXCEPTION("br.com.viktor.javawebpoc.exception.methodnotsupported"),

VALIDATION_INVALID("br.com.viktor.javawebpoc.validation.invalid"),
VALIDATION_FIELD_REQUIRED("br.com.viktor.javawebpoc.validation.fieldrequired"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
br.com.viktor.javawebpoc.exception.javawebpocexception=There was an internal error
br.com.viktor.javawebpoc.exception.javawebpocexception=There was an internal error.

br.com.viktor.javawebpoc.exception.alreadyexistsexception=Argument already exists
br.com.viktor.javawebpoc.exception.alreadyexistsexception=Argument already exists.
br.com.viktor.javawebpoc.exception.studentexistsexception=Student already exists: {0}

br.com.viktor.javawebpoc.exception.nullargumentexception=Null argument: {0}
br.com.viktor.javawebpoc.exception.argumentexception=Invalid argument: {0}
br.com.viktor.javawebpoc.exception.invalidstudentexception=Invalid Student: {0}
br.com.viktor.javawebpoc.exception.nullargumentexception=Null argument: {0}.
br.com.viktor.javawebpoc.exception.argumentexception=Invalid argument: {0}.
br.com.viktor.javawebpoc.exception.invalidstudentexception=Invalid Student: {0}.

br.com.viktor.javawebpoc.exception.notfoundexception=Not found.

br.com.viktor.javawebpoc.exception.jsonbadrequest=JSON has an invalid format.
br.com.viktor.javawebpoc.exception.methodnotsupported=HTTP method not supported.

br.com.viktor.javawebpoc.exception.notfoundexception=Not found
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
br.com.viktor.javawebpoc.exception.javawebpocexception=Houve um erro interno na aplica��o
br.com.viktor.javawebpoc.exception.javawebpocexception=Houve um erro interno na aplicação.

br.com.viktor.javawebpoc.exception.alreadyexistsexception=Argumento j� existente
br.com.viktor.javawebpoc.exception.studentexistsexception=Estudante j� existente: {0}
br.com.viktor.javawebpoc.exception.alreadyexistsexception=Argumento existente.
br.com.viktor.javawebpoc.exception.studentexistsexception=Estudante existente: {0}

br.com.viktor.javawebpoc.exception.nullargumentexception=Argumento nulo: {0}
br.com.viktor.javawebpoc.exception.argumentexception=Argumento inv�lido: {0}
br.com.viktor.javawebpoc.exception.invalidstudentexception=Estudante inv�lido: {0}
br.com.viktor.javawebpoc.exception.nullargumentexception=Argumento nulo: {0}.
br.com.viktor.javawebpoc.exception.argumentexception=Argumento inválido: {0}.
br.com.viktor.javawebpoc.exception.invalidstudentexception=Estudante inválido: {0}.

br.com.viktor.javawebpoc.exception.notfoundexception=Não encontrado.

br.com.viktor.javawebpoc.exception.jsonbadrequest=O JSON está mal formado.
br.com.viktor.javawebpoc.exception.methodnotsupported=Método HTTP não disponível.

br.com.viktor.javawebpoc.exception.notfoundexception=N�o encontrado

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
br.com.viktor.javawebpoc.validation.studentinvalid=Invalid student.
br.com.viktor.javawebpoc.validation.studentnamesize=Student's name have to be between {0} and {1} caracters long.
br.com.viktor.javawebpoc.validation.studentnamenull=Student's name cannot be null.


br.com.viktor.javawebpoc.student=student
br.com.viktor.javawebpoc.name=name


br.com.viktor.javawebpoc.validation.invalid=Invalid {0}.
br.com.viktor.javawebpoc.validation.fieldrequired=The {0} is required.
br.com.viktor.javawebpoc.validation.stringlength=The {0} needs to be between {1} and {2} characters.
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
br.com.viktor.javawebpoc.validation.studentinvalid=Estudante inv�lido
br.com.viktor.javawebpoc.validation.studentnamesize=O nome do estudante precisa estar entre {0} e {1} caracters
br.com.viktor.javawebpoc.validation.studentnamenull=O nome do estudante n�o pode ser vazio
br.com.viktor.javawebpoc.validation.studentinvalid=Estudante inválido.
br.com.viktor.javawebpoc.validation.studentnamesize=O nome do estudante precisa estar entre {0} e {1} caracteres.
br.com.viktor.javawebpoc.validation.studentnamenull=O nome do estudante não pode ser vazio.


br.com.viktor.javawebpoc.student=estudante
br.com.viktor.javawebpoc.name=nome


br.com.viktor.javawebpoc.validation.invalid=Invalido {0}.
br.com.viktor.javawebpoc.validation.fieldrequired=A(o) {0} é obrigatório.
br.com.viktor.javawebpoc.validation.stringlength=A(o) {0} precisa ter entre {1} e {2} caracteres.
2 changes: 1 addition & 1 deletion javawebpoc-web/src/main/resources/localizationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
<value>l10n/javawebpocValidation</value>
</array>
</property>
<property name="defaultEncoding" value="UTF-8"/>
</bean>

</beans>