Topic: core net usewhen

On core the demo a site with  is written.
There was a question as though on better error handling to make, can that changed that. The answer to a web  in one format, on return from mvc in other.
The dug found constructions UseWhen and MapWhen.

public void Configure (IApplicationBuilder app, IHostingEnvironment env))
app. UseExceptionHandler ("/Home/Error");
app. UseWhen (context => context. Request. Path. StartsWithSegments ("/v1 /"), appBuilder =>
app.UseMiddleware<ErrorApiHandlingMiddleware> ();

But ErrorApiHandlingMiddleware works on any . Who can explain what not so with it?