extract error handler logic into handler.go. also add comment for format.go purpose