Skip to content

Commit 58db722

Browse files
authored
fix: return readable errors for unrecognised JSON fields (#580)
When the API received a request body containing unknown JSON fields, it previously returned an opaque or unhelpful error response that gave clients no actionable information. This fix adds proper handling in GlobalExceptionHandler for deserialization failures so that clients receive a clear error message identifying the unrecognised field. This improves the developer experience when integrating with the API and reduces debugging friction. The mentorship page feedback content is also refreshed with 2025 cycle testimonials and link field ordering is aligned with the CMS schema convention.
1 parent 0cd2770 commit 58db722

2 files changed

Lines changed: 44 additions & 26 deletions

File tree

src/main/java/com/wcc/platform/configuration/GlobalExceptionHandler.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,27 @@
44
import static org.springframework.http.HttpStatus.NOT_FOUND;
55

66
import com.fasterxml.jackson.databind.JsonMappingException;
7+
import com.fasterxml.jackson.databind.JsonMappingException.Reference;
78
import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
8-
import com.wcc.platform.domain.exceptions.*;
9+
import com.wcc.platform.domain.exceptions.ApplicationMenteeWorkflowException;
10+
import com.wcc.platform.domain.exceptions.ApplicationNotFoundException;
11+
import com.wcc.platform.domain.exceptions.ContentNotFoundException;
12+
import com.wcc.platform.domain.exceptions.DuplicatedException;
13+
import com.wcc.platform.domain.exceptions.EmailSendException;
14+
import com.wcc.platform.domain.exceptions.ErrorDetails;
15+
import com.wcc.platform.domain.exceptions.ForbiddenException;
16+
import com.wcc.platform.domain.exceptions.InvalidProgramTypeException;
17+
import com.wcc.platform.domain.exceptions.MemberNotFoundException;
18+
import com.wcc.platform.domain.exceptions.MenteeNotSavedException;
19+
import com.wcc.platform.domain.exceptions.MenteeRegistrationLimitException;
20+
import com.wcc.platform.domain.exceptions.MentorNotFoundException;
21+
import com.wcc.platform.domain.exceptions.MentorStatusException;
22+
import com.wcc.platform.domain.exceptions.MentorshipCycleClosedException;
23+
import com.wcc.platform.domain.exceptions.PlatformInternalException;
24+
import com.wcc.platform.domain.exceptions.TemplateValidationException;
925
import com.wcc.platform.repository.file.FileRepositoryException;
1026
import jakarta.validation.ConstraintViolationException;
27+
import java.util.List;
1128
import java.util.NoSuchElementException;
1229
import java.util.stream.Collectors;
1330
import java.util.stream.IntStream;
@@ -22,6 +39,7 @@
2239
import org.springframework.web.context.request.WebRequest;
2340

2441
/** Global controller to handle all exceptions for the API. */
42+
@SuppressWarnings({"PMD.ExcessiveImports"})
2543
@RestControllerAdvice
2644
public class GlobalExceptionHandler {
2745

@@ -190,7 +208,7 @@ private String extractReadableMessage(final HttpMessageNotReadableException ex)
190208
return cause.getMessage();
191209
}
192210

193-
private String formatPath(final java.util.List<JsonMappingException.Reference> path) {
211+
private String formatPath(final List<Reference> path) {
194212
if (path.isEmpty()) {
195213
return "$";
196214
}

src/main/resources/init-data/mentorshipPage.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,59 +9,59 @@
99
"mentorSection": {
1010
"title": "Become a Mentor",
1111
"description": "You should apply to be a mentor if you:",
12+
"link": {
13+
"label": "Join as a mentor",
14+
"uri": "/mentorship/mentor-registration"
15+
},
1216
"items": [
1317
"Want to extend your professional network",
1418
"Want to contribute to the community",
1519
"You are ready to share expertise",
1620
"You want to get a new perspective and learn from your mentees"
17-
],
18-
"link": {
19-
"label": "Join as a mentor",
20-
"uri": "/mentorship/mentor-registration"
21-
}
21+
]
2222
},
2323
"menteeSection": {
2424
"title": "Become a Mentee",
2525
"description": "You should apply to be a mentee if you:",
26+
"link": {
27+
"label": "Check our mentors",
28+
"uri": "/mentorship/mentors"
29+
},
2630
"items": [
2731
"Want to start career in software engineering",
2832
"Want to find a better job",
2933
"Want to be promoted at work",
3034
"Want to apply for a leadership position",
3135
"Need support in advancing your career"
32-
],
33-
"link": {
34-
"label": "Check our mentors",
35-
"uri": "/mentorship/mentors"
36-
}
36+
]
3737
},
3838
"feedbackSection": {
3939
"title": "What do participants think about our Mentorship Programme?",
4040
"feedbacks": [
4141
{
42-
"name": "Lucy",
43-
"feedback": "It is great to be able to share my experience as a newbie in Tech with someone that has more years and experience in the industry. It has definitely made me feel more comfortable with been a completely beginner again and confident that, if a put the hours in, one day it will be pay off.",
44-
"memberType": "Mentor",
45-
"year": 2024
42+
"name": "Busra",
43+
"feedback": "My session with my mentor exceeded my expectations. She's calm, caring, and incredibly knowledgeable. She offered valuable guidance not only on my career but also on life in general. My mentor truly embodies a growth mindset. I highly recommend her to any mentee seeking direction delivered with both compassion and wisdom.",
44+
"memberType": "Mentee",
45+
"year": 2025
4646
},
4747
{
48-
"name": "Ana Smith",
49-
"feedback": "I am exciting with this mentorship program. This is really help me to pursue my goals. I got encouragement, insights, knowledge from my mentor that makes me back on the track and focus to what I have now, upgrade it, then reach out my goals.",
48+
"name": "Zayna",
49+
"feedback": "My mentor really took the time to comprehend my mental barriers and gave personalised structure advice to move past them. I appreciated the mentors vulnerability in explaining similar scenarios they had been in to give me a sense of guidance and belonging. Their kindness and warmth during the session has really helped me to progress in my career due to feeling safe to open up to them.",
5050
"memberType": "Mentee",
51-
"year": 2024
51+
"year": 2025
5252
},
5353
{
54-
"name": "Jane",
55-
"feedback": "My mentor has done an excellent job accommodating me and guiding me this year. This was my first experience as a mentee and it has taken time getting my footing. I entered this program because I felt isolated since I seemed to not have any clarity of my career and had a sense of general \"directionless\". Mentor has made me feel validated in my feeling and has helped me understand that my anxiety stems from not having a good understanding of the industry I hope to be a part of. Through our sessions and an exercise she gave me, I was gained a better perceptive on how exactly to direct my focus.",
56-
"memberType": "Mentor",
57-
"year": 2024
54+
"name": "Anonymous",
55+
"feedback": "Just the simple act of presenting my profile and explaining my difficulties to a professional helped me structure the ideas and information in my head, and that alone was a big help. My mentor was caring, involved, and encouraging.",
56+
"memberType": "Mentee",
57+
"year": 2025
5858
},
5959
{
60-
"name": "Anonymous",
61-
"feedback": "It is an extremely helpful program and the mentor is quite open with matching my needs. She also actively encourages me with when and how to make job applications. She has helped with reviewing my CV and Linkedin profile. We have started work on my own personal project and collaboratively code on it, with the mentor asking questions to reinforce learning.",
60+
"name": "Hanna",
61+
"feedback": "I am delighted to have had the opportunity to work with my mentor. Her explanations are always clear and thorough, and her enthusiasm and passion for our profession are truly contagious.\n Working with her has not only been educational but also incredibly motivating. Her guidance and support have given me a significant boost in my professional development. I am sincerely grateful to her for the valuable insights and encouragement she has provided.\nThank you!",
6262
"memberType": "Mentee",
6363
"year": 2024
6464
}
6565
]
6666
}
67-
}
67+
}

0 commit comments

Comments
 (0)