routes: refactor common api err handling