What episode does Luffy almost get executed

I'm talking about episode 52, in Loguetown, where luffy gets "captured" by Buggy in the execution platform where Roger was executed. Luffy had already given up on life for such a stupid mistake, so much for being king of pirates. But he gets saved by the most random deus ex machina I've seen.

I just want to know your guys opinion on this part, without spoiling cause I'm just in this part of the anime. Personally I have mixed feelings about it. It felt like a really lazy way to introduce/foreshadow whatever that thunder Dragon guy is, while also "disrespecting" on luffy's character and dream. It left me with a sour taste on my mouth to know luffy's journey and dream could've ended so easily by someone like Buggy just because he was being dumb, although he has already shown to be smart when necessary.