update API to render errors JSON properly