[Scala] minor improvements

- remove code duplication on error responses
- handle exceptions when parsing request
- (style) fixed trailing whitespace
- (style) added return types to public methods
- (style) put { .. } around body of finally and while blocks