Parcourir la source

ErrorDetail and readme fix

Mitch Taylor il y a 8 ans
Parent
révision
38173b1e56
2 fichiers modifiés avec 55 ajouts et 4 suppressions
  1. 4
    4
      README.md
  2. 51
    0
      src/main/java/dtos/error/ErrorDetail.java

+ 4
- 4
README.md Voir le fichier

@@ -491,7 +491,7 @@ public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundExcepti
491 491
 
492 492
 
493 493
 
494
-## Part 5.4 - Validating domain entities
494
+## Part 5.5 - Validating domain entities
495 495
 
496 496
 Now it's time to make sure that all objects persisted to the database actually contain valid values. Use the `org.hibernate.validator.constraints.NotEmpty` and `javax.validation.constraints.Size` and `javax.validation.Valid` annotations for validation.
497 497
 
@@ -500,7 +500,7 @@ Now it's time to make sure that all objects persisted to the database actually c
500 500
   - `question` should be `@NotEmpty`
501 501
 - To enforce these validations, add `@Valid` annotations to Poll objects in `RequestMapping`-annotated controller methods (there should be 2)
502 502
 
503
-## Part 5.5 - Customizing validation errors
503
+## Part 5.6 - Customizing validation errors
504 504
 
505 505
 In order to customize validation errors we'll need a class for error information. Create a `ValidationError` class in `io.zipcoder.tc_spring_poll_application.dto.error` with the following fields and appropriate getters and setters:
506 506
 
@@ -510,7 +510,7 @@ In order to customize validation errors we'll need a class for error information
510 510
 We also need a new field in the `ErrorDetail` class to hold errors. There may be multiple validation errors associated with a request, sometimes more than one of the same type, so this field will be a collection, specifically a `Map<String, List<ValidationError>> errors` field.
511 511
 
512 512
 
513
-## Part 5.6 - Create a validation error handler
513
+## Part 5.7 - Create a validation error handler
514 514
 
515 515
 - add below handler to `RestExceptionHandler`
516 516
 
@@ -544,7 +544,7 @@ for(FieldError fe : fieldErrors) {
544 544
 }
545 545
 ```
546 546
 
547
-## Part 5.7 - Externalize strings in a messages.properties file
547
+## Part 5.8 - Externalize strings in a messages.properties file
548 548
 
549 549
 Commonly used strings in your Java program can be removed from the source code and placed in a separate file. This is called externalizing, and is useful for allowing changes to text displayed without impacting actual program logic. One example of where this is done is in internationalization, the practice of providing multilingual support in an application, allowing users to use an application in their native language.
550 550
 

+ 51
- 0
src/main/java/dtos/error/ErrorDetail.java Voir le fichier

@@ -0,0 +1,51 @@
1
+package dtos.error;
2
+
3
+public class ErrorDetail {
4
+
5
+    private String title;
6
+    private int status;
7
+    private String detail;
8
+    private long timeStamp;
9
+    private String developerMessage;
10
+
11
+    public String getTitle() {
12
+        return title;
13
+    }
14
+
15
+    public void setTitle(String title) {
16
+        this.title = title;
17
+    }
18
+
19
+    public int getStatus() {
20
+        return status;
21
+    }
22
+
23
+    public void setStatus(int status) {
24
+        this.status = status;
25
+    }
26
+
27
+    public String getDetail() {
28
+        return detail;
29
+    }
30
+
31
+    public void setDetail(String detail) {
32
+        this.detail = detail;
33
+    }
34
+
35
+    public long getTimeStamp() {
36
+        return timeStamp;
37
+    }
38
+
39
+    public void setTimeStamp(long timeStamp) {
40
+        this.timeStamp = timeStamp;
41
+    }
42
+
43
+    public String getDeveloperMessage() {
44
+        return developerMessage;
45
+    }
46
+
47
+    public void setDeveloperMessage(String developerMessage) {
48
+        this.developerMessage = developerMessage;
49
+    }
50
+
51
+}