← Back to Articles         
Error Handling - Interview Questions

Error Handling - Interview Questions

Published on 12 Oct 2026     4 min read Angular
Quick Revision

1. How do you handle API errors in Angular?

Use RxJS catchError() or the subscribe() error callback to handle API failures. Display user-friendly messages and log technical details appropriately.

this.http.get('/api/users').pipe(
  catchError(err => { console.error(err); return EMPTY; })
).subscribe();

2. How do you globally handle HTTP errors?

Use a functional HTTP interceptor with catchError() to handle common API errors centrally, such as 401, 403, and 500.

export const errorInterceptor: HttpInterceptorFn = (req, next) =>
  next(req).pipe(catchError(err => { console.error(err.status); return throwError(() => err); }));

3. How do you handle 400 Bad Request?

400 indicates an invalid request, such as incorrect input or failed validation. Display validation messages and allow the user to correct the data.

if (error.status === 400) {
  this.errorMessage = 'Invalid request data';
}

4. How do you handle 401 Unauthorized?

401 indicates missing, invalid, or expired authentication credentials. Attempt token refresh if supported; otherwise, clear the session and redirect to login.

if (error.status === 401) {
  this.authService.logout();
}

5. How do you handle 403 Forbidden?

403 indicates the user is authenticated but lacks permission to access the resource. Display an access-denied message or navigate to a forbidden page.

if (error.status === 403) {
  this.router.navigate(['/forbidden']);
}

6. How do you handle 404 Not Found?

404 indicates the requested API endpoint or resource does not exist. Display a meaningful message or redirect to a Not Found page.

if (error.status === 404) {
  this.router.navigate(['/not-found']);
}

7. How do you handle 500 Internal Server Error?

500 indicates an unexpected server-side failure. Display a generic error message and log detailed exception information on the ASP.NET Core server.

if (error.status === 500) {
  this.errorMessage = 'Something went wrong. Please try again.';
}

8. How do you display ASP.NET Core validation errors in Angular forms?

ASP.NET Core commonly returns ValidationProblemDetails containing an errors dictionary. Angular maps these errors to the corresponding form controls.

const messages = error.error?.errors?.['Email'];
this.form.get('email')?.setErrors({ server: messages?.[0] });

Key Point: Display server errors using hasError('server') and the control's error message.

9. How do you implement centralized exception handling in ASP.NET Core?

Use IExceptionHandler or UseExceptionHandler() middleware to handle unhandled exceptions globally. Log exceptions and return consistent error responses.

builder.Services.AddProblemDetails();
app.UseExceptionHandler();

Key Point: Avoid exposing stack traces or sensitive exception details to clients.

10. How should Angular consume ASP.NET Core ProblemDetails responses?

Angular should read standardized ProblemDetails fields such as status, title, detail, and errors when available. Display safe messages and handle errors based on HTTP status.

const problem = error.error;
this.errorMessage = problem?.detail || problem?.title || 'Request failed';

Key Point: Use HttpErrorResponse for HTTP status and ProblemDetails for structured error information.

 

Important Interview Revision Points

Concept

Key Point

catchError()

Handles Observable errors

HTTP Interceptor

Centralized HTTP error handling

400

Bad Request / Validation

401

Authentication required or invalid

403

Access denied

404

Resource not found

500

Internal server error

ValidationProblemDetails

Structured validation errors

ProblemDetails

Standardized API error response

IExceptionHandler

Centralized ASP.NET Core exception handling

UseExceptionHandler()

Global exception middleware

HttpErrorResponse

Angular HTTP error information

Angular + ASP.NET Core Error Handling Flow

Angular Component
       |
       v
Angular API Service
       |
       v
HTTP Error Interceptor
       |
       v
ASP.NET Core Web API
       |
       v
Exception Handling Middleware
       |
       | Log Exception
       | Generate ProblemDetails
       v
HTTP Error Response
       |
       v
Angular Error Interceptor
       |
       | 400 → Show Validation Errors
       | 401 → Refresh Token / Login
       | 403 → Access Denied
       | 404 → Not Found
       | 500 → Generic Error Message
       v
Angular Component / UI

Interview priority: Focus particularly on questions 1, 2, 3, 4, 5, 8, 9, and 10.

Key interview takeaway: Use Angular HTTP interceptors for centralized HTTP error handling, ASP.NET Core exception middleware for server-side exceptions, and ProblemDetails for consistent error responses.

← Back to Articles