Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Chris1904's avatar

Which http status code for invalid coupons?

Hi there,

Not having much experience working with error codes, I am running into this scenario: I offer the use of coupons and depending on if the coupon is valid or not, I would like to display the appropriate error message.

I, at first, was using "204 - No Content codes", but realized that since that status code does not accept a body it would be sufficient for coupon codes that do not exist, but in case the order does not reach the minimum dollar amount (or whatever other reason the coupon does not meet the requirements) the coupon would also be invalid. Hence, I would have to display the appropriate error message.

What would be the proper http response status code for my use case?

Thanks for any advice!

Chris

0 likes
2 replies
robrogers3's avatar
Level 37

meh, just go for it! 500!

kidding.

if there is no matching code. return response(404, 'Coupon Code Not Found');

if there if the coupon is invalid for some reason return response(422, 'The Coupon you supplied does not work here. Dude!).

Personally I love 418. Hilarious.

Btw, if your webapp has a lot of js with ajax responses use this: https://packagist.org/packages/robrogers3/laravel-jsonaware-exception-handler

Yeah, I wrote it but expressly for this purpose. it does this:

Provide Meaningful Ajax error messages for your Laravel Project.

Every one likes cool error message pages. Github has an awesome 404.

And it's very easy to create your own custom error pages for html responses.

But doing this for Ajax and Json responses meant either doing something generic or figuring out your own solution. Often something like returning an error message like 'Sorry we cant handle your request'. Nothing informative.

This package solves this problem.

Give it a whirl. It just works. Plus you get to customize your messages returned!

1 like
raza22sid's avatar

If you're running a deals or coupon site (like mine — Couponztime 👀), the best status code for invalid or expired coupons is 410 Gone.

It basically tells Google: “Hey, this page is gone forever, don’t bother coming back.” Way better than 404 if the coupon is permanently expired.

But if you think the coupon might come back, then 404 works too — just don’t leave broken links lying around forever.

What I do on my site is keep the expired coupon page live, but show a little message like “This offer has expired” so people know — and I don’t lose that traffic or backlinks. Then if it’s totally useless, I use 410.

Hope that helps anyone running similar coupon or promo pages!

Please or to participate in this conversation.