Store code for API errors in exception, use asserts in tests