Log error messages when API controller catches them

And some small refactorings.

References rapidftr/tracker#106