Employee Management System Handling Exception

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The Employee Management System that we developed, works functionally; however, it needs to handle the exceptions properly.

Prerequisite

  • User should refer to this code that we’ll work upon.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Handle Exception

The current test report for the employee management system has some failures. Handle exception

  1. test_delete_employee is failing because the expected status code is 204, but our API returned 200.
  2. test_create_employee is failing because it expects status code 201, but our API returned 200.
  3. test_GetEmployee_employeeNotFound is failing because our service throws the exception EmployeeNotFoundException, which is not handled in the web layer.

Let's go ahead and fix each of them.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Fix Delete Employee API

Spring boot always defaults to the status code 200 OK if API does not return the status code explicitly. To return specific HTTP code, spring boot provides annotation @ResponseStatus, which should be applied to the handler method. Our code change with the fix will be.

Fix Create New Employee

The same change applies to creating an employee method.

Applying the above changes leaves us with only one failure. Fix create new employee

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Fix Employee Not Found Exception

Here, we need to use controller advice to handle exceptions and return meaningful content to the user. We need to return a custom response to the user. Let's do that.

1. Create a custom response POJO.

2. Write controller advice

The above code intercepts the exception and returns the response to the user with the status code 404, which goes well with REST.

Our latest test report. Fix employee not found exception Test Report

The actual response to the API caller Fix employee not found exception Actual Response

Complete source code is available at GitHub location under tag version_7.0.0.

Conclusion

In this article, we have

  • Improved employee management system to be more RESTful.
  • Handled exceptions and returned a meaningful response to the user.