add api_error
move api_error to util package and include some nice generics
remove debugging printing from authenticate route
extract ToJson and add generic ResourceResponse helper