make encoder safer

actually test encoder
add test cases for common api/server errors