Bird
0
0

Given this code snippet:

medium📝 Predict Output Q5 of 15
Angular - HTTP Client
Given this code snippet:
this.http.post('/api/items', {name: 'Book'}).subscribe({next: res => console.log('Success'), error: err => console.log('Error')});

What will be logged if the server returns an error?
AError
BNothing
CSuccess
DThrows exception
Step-by-Step Solution
Solution:
  1. Step 1: Analyze subscribe error callback

    The error callback logs 'Error' when the server returns an error.
  2. Step 2: Confirm output on server error

    Since server returns error, 'Error' will be logged.
  3. Final Answer:

    Error -> Option A
  4. Quick Check:

    Server error triggers error callback = C [OK]
Quick Trick: Use error callback to handle POST errors [OK]
Common Mistakes:
MISTAKES
  • Expecting success log on error
  • Not handling error callback
  • Assuming exception thrown automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes