I have a Yellow Lab that does that sometimes. I've had the fish for over a year and it's still fine. How long have you had the fish? Does it eat? If it does I wouldn't worry about it.
I'd say if he's eating he's fine. One of Yellow Lab's I have acts like that. He'll also swim fast up and down a corner of the aquarium for a while then settles down. He eats good and looks healthy other than the erratic swimming.