Fix error logging if it is Error object + add unit tests