Add more api tests, and improve api err handler