-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #600 from puzzle/feature/576-toaster-styling
Feature/576 toaster styling and error msg's
- Loading branch information
Showing
60 changed files
with
1,507 additions
and
832 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
backend/src/main/java/ch/puzzle/okr/OkrErrorAttributes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ch.puzzle.okr; | ||
|
||
import ch.puzzle.okr.models.OkrResponseStatusException; | ||
import org.springframework.boot.web.error.ErrorAttributeOptions; | ||
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.context.request.WebRequest; | ||
|
||
import java.util.Map; | ||
|
||
@Component | ||
public class OkrErrorAttributes extends DefaultErrorAttributes { | ||
|
||
@Override | ||
public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) { | ||
Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, options); | ||
|
||
Throwable throwable = getError(webRequest); | ||
if (throwable instanceof OkrResponseStatusException exception) { | ||
errorAttributes.put("errors", exception.getErrors()); | ||
} | ||
return errorAttributes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ch.puzzle.okr.dto; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class ErrorDto { | ||
private final String errorKey; | ||
private final List<String> params; | ||
|
||
public ErrorDto(String errorKey, List<Object> params) { | ||
this.errorKey = errorKey; | ||
this.params = params.stream().map(Object::toString).toList(); | ||
} | ||
|
||
public ErrorDto(String errorKey, String param) { | ||
this(errorKey, List.of(param)); | ||
} | ||
|
||
public String getErrorKey() { | ||
return errorKey; | ||
} | ||
|
||
public List<String> getParams() { | ||
return params; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
ErrorDto errorDto = (ErrorDto) o; | ||
return Objects.equals(errorKey, errorDto.errorKey) && Objects.equals(params, errorDto.params); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(errorKey, params); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package ch.puzzle.okr.models; | ||
|
||
public class ErrorMsg { | ||
private ErrorMsg() { | ||
} | ||
|
||
public static final String UNAUTHORIZED = "UNAUTHORIZED"; | ||
public static final String NOT_FOUND = "NOT_FOUND"; | ||
public static final String KEYRESULT_CONVERSION = "KEYRESULT_CONVERSION"; | ||
public static final String ALREADY_EXISTS_SAME_NAME = "ALREADY_EXISTS_SAME_NAME"; | ||
public static final String CONVERT_TOKEN = "CONVERT_TOKEN"; | ||
public static final String DATA_HAS_BEEN_UPDATED = "DATA_HAS_BEEN_UPDATED"; | ||
// Model | ||
public static final String MODEL_NULL = "MODEL_NULL"; | ||
public static final String MODEL_WITH_ID_NOT_FOUND = "MODEL_WITH_ID_NOT_FOUND"; | ||
|
||
// Attributes | ||
public static final String ATTRIBUTE_NULL = "ATTRIBUTE_NULL"; | ||
public static final String ATTRIBUTE_NOT_NULL = "ATTRIBUTE_NOT_NULL"; | ||
public static final String ATTRIBUTE_CHANGED = "ATTRIBUTE_CHANGED"; | ||
public static final String ATTRIBUTE_NOT_BLANK = "ATTRIBUTE_NOT_BLANK"; | ||
public static final String ATTRIBUTE_NOT_VALID = "ATTRIBUTE_NOT_VALID"; | ||
public static final String ATTRIBUTE_SIZE_BETWEEN = "ATTRIBUTE_SIZE_BETWEEN_{min}_{max}"; | ||
public static final String ATTRIBUTE_SET_FORBIDDEN = "ATTRIBUTE_SET_FORBIDDEN"; | ||
public static final String ATTRIBUTE_NOT_SET = "ATTRIBUTE_NOT_SET"; | ||
public static final String ATTRIBUTE_CANNOT_CHANGE = "ATTRIBUTE_CANNOT_CHANGE"; | ||
public static final String ATTRIBUTE_MIN_VALUE = "ATTRIBUTE_MIN_VALUE_{value}"; | ||
public static final String ATTRIBUTE_MAX_VALUE = "ATTRIBUTE_MAX_VALUE_{value}"; | ||
|
||
public static final String NOT_AUTHORIZED_TO_READ = "NOT_AUTHORIZED_TO_READ"; | ||
public static final String NOT_AUTHORIZED_TO_WRITE = "NOT_AUTHORIZED_TO_WRITE"; | ||
public static final String NOT_AUTHORIZED_TO_DELETE = "NOT_AUTHORIZED_TO_DELETE"; | ||
public static final String TOKEN_NULL = "TOKEN_NULL"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
backend/src/main/java/ch/puzzle/okr/models/OkrResponseStatusException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package ch.puzzle.okr.models; | ||
|
||
import ch.puzzle.okr.dto.ErrorDto; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.util.List; | ||
|
||
public class OkrResponseStatusException extends ResponseStatusException { | ||
|
||
private final List<ErrorDto> errors; | ||
|
||
public OkrResponseStatusException(HttpStatus status, String errorKey) { | ||
this(status, errorKey, List.of()); | ||
} | ||
|
||
public OkrResponseStatusException(HttpStatus status, String errorKey, List<Object> objectParams) { | ||
this(status, List.of(new ErrorDto(errorKey, objectParams))); | ||
} | ||
|
||
public OkrResponseStatusException(HttpStatus status, String errorKey, String param) { | ||
this(status, errorKey, List.of(param)); | ||
} | ||
|
||
public OkrResponseStatusException(HttpStatus status, ErrorDto error) { | ||
this(status, List.of(error)); | ||
} | ||
|
||
public OkrResponseStatusException(HttpStatus status, List<ErrorDto> errors) { | ||
super(status, errors.get(0).getErrorKey()); | ||
this.errors = errors; | ||
} | ||
|
||
public List<ErrorDto> getErrors() { | ||
return errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.