(API) 404 response as HTML

I am on ERPnext v12, When ever there is 404 response over API, the response comes as html instead of JSON.

The error printed as text as mentioned in the following image.

well quick solution is just intersept the status code like
if( status_code == 404) {
through something went wrong
}

Actual I need to read the exact error and show it within my application.