Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Question on 404 (not technical, I just want opinions)

Question on 404 (not technical, I just want opinions)

Scheduled Pinned Locked Moved The Lounge
csharpjavascriptsysadminquestionwcf
38 Posts 26 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Sander RosselS Offline
    Sander RosselS Offline
    Sander Rossel
    wrote on last edited by
    #1

    I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

    Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

    OriginalGriffO Kornfeld Eliyahu PeterK L G G 23 Replies Last reply
    0
    • Sander RosselS Sander Rossel

      I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

      Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      I'd have to that that from a user perspective, a 404 normally means "oops! I moved it" and that it might come back if I retry in an hour or so. A specific "that product cannot be found" means "the Elephants don't stock that anymore" and I'll look for an equivelant, or go elsewhere to someone who does.

      Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      D 1 Reply Last reply
      0
      • Sander RosselS Sander Rossel

        I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

        Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        A further thought: if I get a 404 and it doesn't "come back later" then I assume the site was written by idiots, or isn't maintained - and I bugger off elsewhere anyway.

        Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        Sander RosselS W 2 Replies Last reply
        0
        • Sander RosselS Sander Rossel

          I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

          Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu PeterK Offline
          Kornfeld Eliyahu Peter
          wrote on last edited by
          #4

          Quote:

          The HTTP 404, 404 Not Found and 404 (pronounced "four oh four") error message is a Hypertext Transfer Protocol (HTTP) standard response code, in computer network communications, to indicate that the client was able to communicate with a given server, but the server could not find what was requested.

          So 404 is the most perfect solution for anything not found in a chain of web request... Not only things related to the server and the resources on it, but also for data related resources... However you may alter the text, it will give two things: 1. 404 is understood by non-human client too 2. Altered text can refer to human client to what exactly the problem...

          Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

          "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

          1 Reply Last reply
          0
          • Sander RosselS Sander Rossel

            I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

            Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

            L Offline
            L Offline
            lmoelleb
            wrote on last edited by
            #5

            When should 404 be returned according to you? It can't be when the server does not exist - because then it can't response. It can't be when the URL is malformed - that would be a bad request. 404 means exactly what it says on the tin: I looked at the location you specified, and I did not find anything - i.e. what you asked for was NOT FOUND. What you are missing is proper logging and health monitoring. :)

            Sander RosselS 1 Reply Last reply
            0
            • Sander RosselS Sander Rossel

              I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

              Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

              G Offline
              G Offline
              GuyThiebaut
              wrote on last edited by
              #6

              Tomato tamata... I think it all comes down to the protocol that has been agreed upon between the consumer and provider so to speak. If you use Swagger you can document this for the consumers - so in the end I don't think it matters too much. Personally I would return a 200 with some info in the body. That said, a 404 can be useful for blocking hacking attempts as it gives hackers the impression that the endpoint does not exist. Tomato tamata...

              “That which can be asserted without evidence, can be dismissed without evidence.”

              ― Christopher Hitchens

              1 Reply Last reply
              0
              • Sander RosselS Sander Rossel

                I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

                Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                G Offline
                G Offline
                GKP1992
                wrote on last edited by
                #7

                We are using a 404 response code for a very similar scenario in Azure functions. But we also log when we send back a 404 with a proper message of what went wrong. For instance, "The product {x} was not found." in your case. So yeah, 404 seems to be the appropriate response as pointed out by @KornfeldEliyahuPeter and @lmoelleb.

                I am not the one who knocks. I never knock. In fact, I hate knocking.

                1 Reply Last reply
                0
                • OriginalGriffO OriginalGriff

                  I'd have to that that from a user perspective, a 404 normally means "oops! I moved it" and that it might come back if I retry in an hour or so. A specific "that product cannot be found" means "the Elephants don't stock that anymore" and I'll look for an equivelant, or go elsewhere to someone who does.

                  Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                  D Offline
                  D Offline
                  den2k88
                  wrote on last edited by
                  #8

                  OriginalGriff wrote:

                  I'd have to that that from a user perspective, a 404 normally means "It don't work, feez eet!"

                  FTFY

                  GCS d-- s-/++ a- C++++ U+++ P- L+@ E-- W++ N+ o+ K- w+++ O? M-- V? PS+ PE- Y+ PGP t+ 5? X R+++ tv-- b+(+++) DI+++ D++ G e++ h--- ++>+++ y+++*      Weapons extension: ma- k++ F+2 X

                  1 Reply Last reply
                  0
                  • OriginalGriffO OriginalGriff

                    A further thought: if I get a 404 and it doesn't "come back later" then I assume the site was written by idiots, or isn't maintained - and I bugger off elsewhere anyway.

                    Bad command or file name. Bad, bad command! Sit! Stay! Staaaay... AntiTwitter: @DalekDave is now a follower!

                    Sander RosselS Offline
                    Sander RosselS Offline
                    Sander Rossel
                    wrote on last edited by
                    #9

                    That's not really what a 404 does, is it? https://www.codeproject.com/something[^] gives you a 404, but it wasn't moved and it's not coming back either :) It just does not exist.

                    Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                    1 Reply Last reply
                    0
                    • L lmoelleb

                      When should 404 be returned according to you? It can't be when the server does not exist - because then it can't response. It can't be when the URL is malformed - that would be a bad request. 404 means exactly what it says on the tin: I looked at the location you specified, and I did not find anything - i.e. what you asked for was NOT FOUND. What you are missing is proper logging and health monitoring. :)

                      Sander RosselS Offline
                      Sander RosselS Offline
                      Sander Rossel
                      wrote on last edited by
                      #10

                      lmoelleb wrote:

                      When should 404 be returned according to you?

                      You're right about the server, of course, and probably also the domain, but when you're trying to call a controller or function that doesn't exist it should return a 404, for example https://www.codeproject.com/something[^]. I agree that when the function exists, but returns no result a 404 might be appropriate, but it becomes a hassle to differentiate between "function does not exist" and "whatever you're looking for does not exist". So what should a search form return if a user searches for the (human) name "123"? 404 or 200 with no results? I'm saying 200, because everything went well, but there is simply no person with name "123" (which is also a valid response) :)

                      Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                      L 1 Reply Last reply
                      0
                      • Sander RosselS Sander Rossel

                        lmoelleb wrote:

                        When should 404 be returned according to you?

                        You're right about the server, of course, and probably also the domain, but when you're trying to call a controller or function that doesn't exist it should return a 404, for example https://www.codeproject.com/something[^]. I agree that when the function exists, but returns no result a 404 might be appropriate, but it becomes a hassle to differentiate between "function does not exist" and "whatever you're looking for does not exist". So what should a search form return if a user searches for the (human) name "123"? 404 or 200 with no results? I'm saying 200, because everything went well, but there is simply no person with name "123" (which is also a valid response) :)

                        Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                        L Offline
                        L Offline
                        lmoelleb
                        wrote on last edited by
                        #11

                        Well, it did find the search result - it was an instance of an empty list which it returned, so 200 with an empty response it is. ;P REST return values are indeed problematic, as is often the case when something is repurposed well beyond the initial design plan (that would be all of HTTP/HTML pretty much). But your original example was not one I would throw into the "problematic bucket". :)

                        1 Reply Last reply
                        0
                        • Sander RosselS Sander Rossel

                          I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

                          Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                          J Offline
                          J Offline
                          Jorgen Andersson
                          wrote on last edited by
                          #12

                          200 OK is in any case wrong, but you have to decide whether this is a Client error or not. All responses in the 400 category are Client Errors. If it's not a client error you should consider 204 No Content

                          Wrong is evil and must be defeated. - Jeff Ello

                          1 Reply Last reply
                          0
                          • Sander RosselS Sander Rossel

                            I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

                            Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                            F Offline
                            F Offline
                            F ES Sitecore
                            wrote on last edited by
                            #13

                            When you are asking a server for a resource you issue a GET with the URI of the resource. If you're looking for a file called home.html you would issue GET /home.html If that resource can't be found the server will respond 404 to let you know. When you are asking a web service for a resource you issue a GET with the URI of the resource. If you're looking for a Product with id of 123 you would issue GET /product/123 If that resource can't be found the server will respond 404 to let you know. In the first case the resource is a file, in the second the resource is the product. You're not thinking about the resource itself, you're thinking about the mechanism to deliver the resource. The fact that the /product controller exists means the mechanism to find the product exists, but the client isn't interested in that, it doesn't care if the delivery mechanism is there, it cares if its product\resource is there. When you ask for /thisdoesnotexist.aspx if we return 200 because the mechanism to deliver the resource exists even if the target resource doesn't then this would return 200 also as the http handler that deals with the aspx pipeline exists, even if it can't fine the relevant aspx file on the file system.

                            Sander RosselS 1 Reply Last reply
                            0
                            • Sander RosselS Sander Rossel

                              I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

                              Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                              1 Offline
                              1 Offline
                              11917640 Member
                              wrote on last edited by
                              #14

                              Talking about desktop development, I always feel uncomfortable to format hard disk, when user types out-of-range value in some textbox.

                              Sander RosselS 1 Reply Last reply
                              0
                              • F F ES Sitecore

                                When you are asking a server for a resource you issue a GET with the URI of the resource. If you're looking for a file called home.html you would issue GET /home.html If that resource can't be found the server will respond 404 to let you know. When you are asking a web service for a resource you issue a GET with the URI of the resource. If you're looking for a Product with id of 123 you would issue GET /product/123 If that resource can't be found the server will respond 404 to let you know. In the first case the resource is a file, in the second the resource is the product. You're not thinking about the resource itself, you're thinking about the mechanism to deliver the resource. The fact that the /product controller exists means the mechanism to find the product exists, but the client isn't interested in that, it doesn't care if the delivery mechanism is there, it cares if its product\resource is there. When you ask for /thisdoesnotexist.aspx if we return 200 because the mechanism to deliver the resource exists even if the target resource doesn't then this would return 200 also as the http handler that deals with the aspx pipeline exists, even if it can't fine the relevant aspx file on the file system.

                                Sander RosselS Offline
                                Sander RosselS Offline
                                Sander Rossel
                                wrote on last edited by
                                #15

                                You do make a valid point. I'm still not sure how to gracefully differentiate between "URL not found" and "Product not found". In my specific case I'm calling a web API that returns a 404 when a product isn't found. However, I need to report 400 "product not found", along with other error messages. In my case a 404 URL not found is more like a 500, I'm calling a URL that doesn't exist. In some other service I have to try and parse the body, if it's a string it's probably an error, else it's a valid request. All those if-elses don't feel very nice though...

                                Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                                M 1 Reply Last reply
                                0
                                • 1 11917640 Member

                                  Talking about desktop development, I always feel uncomfortable to format hard disk, when user types out-of-range value in some textbox.

                                  Sander RosselS Offline
                                  Sander RosselS Offline
                                  Sander Rossel
                                  wrote on last edited by
                                  #16

                                  No one was talking about desktop development... But formatting a disk sounds like a good plan, maybe we should implement that on our back-end too! :thumbsup:

                                  Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                                  1 1 Reply Last reply
                                  0
                                  • Sander RosselS Sander Rossel

                                    I'm wondering, what are your opinions on this. My current employer uses 404 in web services when some entity cannot be found. For example, let's say we're trying to get product x, but x does not exist. Personally, I'd opt for a 200 with an empty response (or a response with a "product could not be found" error). But here, they return a 404. Why am I against returning a 404? Because the server exists, the URL exists, the web service exists, so technically everything was found. According to Wikipedia "The website hosting server will typically generate a "404 Not Found" web page when a user attempts to follow a broken or dead link;", but the link isn't broken! I've ran into trouble because I don't want to throw an exception on 404, but I never know if some service could not be reached or if an invalid entity was requested. In one case I returned the error "Product x could not be found" to a front-end, while in reality the configuration was wrong and the URL to the web service was broken. I'd understand this on a website, where you browse to mydomain.com/product/x, but a web service? So... Opinions? Do you use 404 to indicate that some object could not be found (in a web service)? I get that we did not find product x, but there must be a better way to separate functional from technical error... How do you handle this?

                                    Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                                    C Offline
                                    C Offline
                                    Chris Maunder
                                    wrote on last edited by
                                    #17

                                    We’ve just had exactly that discussion at CodeProject. 404 means “The server has not found anything matching the Request-URI” This doesn’t only mean it can’t find a page. It also means it can be used if it can’t find a resource corresponding to the URI. It’s used when you want to say ‘can’t find it but I’m not going to give you any further info on why’

                                    cheers Chris Maunder

                                    M 1 Reply Last reply
                                    0
                                    • Sander RosselS Sander Rossel

                                      No one was talking about desktop development... But formatting a disk sounds like a good plan, maybe we should implement that on our back-end too! :thumbsup:

                                      Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                                      1 Offline
                                      1 Offline
                                      11917640 Member
                                      wrote on last edited by
                                      #18

                                      Actually, I share your feeling that 404 is too much for "Product x could not be found" case. But probably my sarcasm was not clear without smiles, I don't like them (old school). So, these smiles provide required emotions for my both posts: :) :) :) :)

                                      Sander RosselS 1 Reply Last reply
                                      0
                                      • C Chris Maunder

                                        We’ve just had exactly that discussion at CodeProject. 404 means “The server has not found anything matching the Request-URI” This doesn’t only mean it can’t find a page. It also means it can be used if it can’t find a resource corresponding to the URI. It’s used when you want to say ‘can’t find it but I’m not going to give you any further info on why’

                                        cheers Chris Maunder

                                        M Offline
                                        M Offline
                                        MadMyche
                                        wrote on last edited by
                                        #19

                                        Exactly. What is being requested (the resource) is not of any particular content-type. The great philosopher Obi-Wan Kenobi in essence returned a 404 when he stated "these aren't the droids you're looking for"


                                        Director of Transmogrification Services Shinobi of Query Language Master of Yoda Conditional

                                        Sander RosselS 1 Reply Last reply
                                        0
                                        • Sander RosselS Sander Rossel

                                          You do make a valid point. I'm still not sure how to gracefully differentiate between "URL not found" and "Product not found". In my specific case I'm calling a web API that returns a 404 when a product isn't found. However, I need to report 400 "product not found", along with other error messages. In my case a 404 URL not found is more like a 500, I'm calling a URL that doesn't exist. In some other service I have to try and parse the body, if it's a string it's probably an error, else it's a valid request. All those if-elses don't feel very nice though...

                                          Best, Sander Continuous Integration, Delivery, and Deployment arrgh.js - Bringing LINQ to JavaScript Object-Oriented Programming in C# Succinctly

                                          M Offline
                                          M Offline
                                          MadMyche
                                          wrote on last edited by
                                          #20

                                          The title for 404 is "Not Found". It is agnostic as to what type of resource is being requested; could be a product, a category, a page, or something else. In my world... - The message returned would be based on the context of the path; if it is a product endpoint then I would say "Product Not Found". Likewise if it was a Category I would say "Category Not Found" - In the above example, if I know the product existed (e.g. via a ProductID) and had been deleted, I would return a "410: Gone" status I suppose a 400 could be used if the requested path was invalid; such as "domain.com/retrieve/porduct/101" as the mis-spelling could be viewed as being an example of malformed request syntax Unless there is a system exception that is not being caught; I do not return 500 errors.


                                          Director of Transmogrification Services Shinobi of Query Language Master of Yoda Conditional

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups