• Eager Eagle
      link
      fedilink
      English
      12 months ago

      That’s not what HTTP errors are about, HTTP is a high level application protocol and its errors are supposed to be around access to resources, the underlying QUIC or TCP will handle most lower level networking nuances.

      Also, 5xx errors are not about incorrect inputs, that’s 4xx.

      • Mak'
        link
        fedilink
        English
        12 months ago

        …HTTP is a high level application protocol and its errors are supposed to be around access to resources…

        I’ve had fellow developers fight me on this point, in much the same way as your parent post.

        “If you return a 404 for a record not found, how will I know I have the right endpoint?”

        You’ll know you have the right endpoint because I advertised it—in Open API, in docs, etc.

        “But, if /users/123 returns a 404, does that mean that the endpoint can’t be found or the record can’t be found?”

        Doesn’t matter. That resource doesn’t exist. So, act appropriately.

        • @Takumidesh@lemmy.world
          link
          fedilink
          22 months ago

          It’s not like you can’t return a body with the 404 that specifies that the user itself is not found versus the ending being wrong.

        • @boonhet@lemm.ee
          link
          fedilink
          12 months ago

          Standardize a response body across your APIs that specifies the cause of the non-2xx response. Have an enum per API/service for causes. Include them in the API doc.

          If anyone still doesn’t get it, quietly dispose of them at your friend’s pig farm.

        • @xthexder@l.sw0.com
          link
          fedilink
          02 months ago

          You can send 4xx errors yourself too. If the client needs to change something about the request, that’s a 4xx, like 400 Bad Request. If the server has an error and it’s not the client’s fault, that’s a 5xx like 502 Bad Gateway.

          The wikipedia listing of all HTTP codes is quite helpful. People also forget you can send a custom response body with a 4xx or 5xx error. So you can still make a custom JSON error message.

            • Eager Eagle
              link
              fedilink
              English
              1
              edit-2
              2 months ago

              A 2xx means success to its requester. If you have an error in step 6 out of 13 that breaks the resource action, you shouldn’t be returning a success.

              You might argue what to return and what kind of information to include in the response (like tracking numbers), but it shouldn’t be a 2xx and I don’t see how a misleading 200 would be more helpful than a 400 bad request.

                • Eager Eagle
                  link
                  fedilink
                  English
                  12 months ago

                  and to just send “Bad request” when it’s a good request - does not make sense

                  That’s when you use a 5xx status, then. The client doesn’t care how many other services you reach out to in order to fulfill their request. A 5xx code also covers failures in other parts of the system.