• reboot6675@sopuli.xyz
    link
    fedilink
    arrow-up
    11
    ·
    5 hours ago

    Been having similar case with dev teams who have coded every error to be 500. User typed the wrong URL? 500. User tried to access a page without logging in? 500… Makes detecting real errors a pain

    • jj4211@lemmy.world
      link
      fedilink
      arrow-up
      5
      ·
      3 hours ago

      I’d easily take that over ‘200 for everything’. If at least errors are distinct from success, I’d take that as a win. My standards have been lowered by so many ‘200 for everything’ backends…

    • Blackmist@feddit.uk
      link
      fedilink
      English
      arrow-up
      7
      ·
      5 hours ago

      And on the other side of this are JS devs that check for neither error response codes or error messages, and write an error into their own data as if it’s the result they were after.

      Always fun to see GET /orders/{error : “invalid branchID provided”} in your logs.

    • homura1650@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      4 hours ago

      I would argue that in your application, a wrong URL is a sever error. That error being improper handling of a client error.

      I’m not a web dev, but had a similar problem with a niche compiler I used to develop.

      We were pretty good at validating invariants at the mid and back-end. This meant that most user errors got reported as internal errors. Generally, these errors were good enough that users were able to get used to reading them and fix their code.

      It was next to impossible to actually get users to file bugs about this. Our internal error messages started with a banner that read “THIS IS A BUG IN <compiler name>. PLEASE REPORT TO <support email address>”. Despite that, whenever we actually got a bug report, it would inevitably start with “I’m pretty sure this isn’t actually a bug in the compiler, but I can’t figure out what I am doing wrong in my code”.

      • jj4211@lemmy.world
        link
        fedilink
        arrow-up
        4
        ·
        3 hours ago

        I would argue that in your application, a wrong URL is a sever error. That error being improper handling of a client error.

        That’s certainly an unusual take. If you are a backend to HTTP and something throws a completely bogus URL out of left field at you, that’s not by any means a backend error.

        I guess your take is that it might be some sort of usability issue or such because if 95% of clients try to hit the same non-existant URL, that probably means there’s some reasonable expectation that you should do something about the URL. However that’s relatively more rare a sort of ‘invalid URL’ scenario. The vast vast majority are some sort of scanners trying bogus crap, followed by an impossibly diverse set of typos and peculiar one-off assumptions that you can’t possibly reasonably cover.

        • homura1650@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          2 hours ago

          If it’s not a backend error, you shouldn’t be throwing a 5xx error code. Since you are throwing a 500, you have a server bug; even if that bug is simply “sends incorrect error code”

          • jj4211@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            1 hour ago

            Ok, got you, thought you were saying a bad url from client was inherently a backend mistake.

  • whoisearth@lemmy.ca
    link
    fedilink
    arrow-up
    30
    ·
    21 hours ago

    Fun story close to a decade ago we were attempting to upgrade our batch scheduler called Tidal to version 6x which had a RESTful API.

    One of the reasons we dropped the product was because we were getting 200 status codes meanwhile the output was a java dump of an error message.

    They were adamant that this was an us problem, no matter how much I tried to explain to them with numerous links explaining to them that if something has a 200 status code that should mean things worked.

    They argued that the 200 meant we were hitting the API fine. We would have to write code to read the return for if it was a error or not. I still don’t think they understood how stupid they were, even all these years later.

    • jj4211@lemmy.world
      link
      fedilink
      arrow-up
      13
      ·
      8 hours ago

      I have had that argument repeatedly with people. People insisting that HTTP error codes are “transport layer” and it’s “wrong” for an API to hijack them to report “application level issues”.

      No, the whole point of “REST” was to map application semantics to HTTP in a way that actually normalizes some things like error handling and expectations around whether an operation could be expected to be idempotent and make the namespace navigable.

      At one point my work announced a person who was an external hire to be the ‘API genius’ to set my company straight. He came from a super reputable well known company so of course he just the smart guy to fix our technical mess. He had sent a message saying that he had reviewed the teams API and concluded they were not restful. I had a glimmer of optimism, that someone recognized as authoritative would call the RPC style HTTP usage that always returned 200 and steer toward sanity, or at least honesty. No, his feedback was that was all fine, but REST does not use JSON, REST uses Protobuf, so they need to change to Protobuf to claim to be REST. Of all the what the hell I could have predicted, that one was not in my book…

      • RedFrank24@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        5 hours ago

        A real “API Genius” would be complaining that your API doesn’t include HATEOAS, even though I’ve never once seen an API be used in that way, and few of the big tech APIs actually use it even though they call their APIs RESTful.

      • enumerator4829@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        7 hours ago

        The number of people talking about REST without having read the wikipedia page is astonishing. Roy Fielding’s dissertation on the subject might be of interest, but that’s from 2000 and absolutely not webscale.

        (Edit: /s if that wasn’t immediately obvious)

        • jj4211@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          2 hours ago

          It’s ok, as long as you make sure to use mongodb it will be webscale no matter what. But if you date use anything else, it won’t be.

    • darvit@lemmy.darvit.nl
      link
      fedilink
      arrow-up
      5
      ·
      23 hours ago

      This looks so over-engineered. Most of the time you only need an error message. Make the message clear enough so that it can be shown to the end user.

      • TomasEkeli@programming.dev
        link
        fedilink
        arrow-up
        3
        ·
        7 hours ago

        Why even use HTTP, when you can just send bytes directly over the physical network card, right?

        Because standards make it better for everyone. You’ve no idea when, who or in what context the error will happen or be received by.

        It takes so little to return ProblemDetails, and improves the experience of devs using your API so much. Just do it. Stop thinking up edge cases and faffing about with excuses. Do it.

        • jj4211@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          2 hours ago

          I think the challenge is that it looks like a lot of other ‘standards’ I’ve seen: on one hand tediously specific yet on the other hand, so open ended as to largely defeat the point.

          Every problem must have a ‘type’. Ok, fine, so what are the semantics of the ‘problem type’? Well, nothing in particular, just has to be defined, but it might be nice if it’s a url telling a human about your own human thoughts on the type. Also, if you encounter multiple ‘errors’, you need to omit any that you arbitrarily fail to group into the same ‘type’ which shouldn’t be subjectively too vague either, so don’t think about making catch-all types so you don’t have to discard some of the errors.

          You can’t count on the members, and a problem type may arbitrarily ‘extend’ to completely rearrange those members into members of child objects instead, but that’s really all up to the backend to decide however they want to arrange it, with no prescribed standard for error bundling, but an example of how a backend could voluntarily implement such bundling as an implementer specific extension if they like, but again, don’t bundle errors that shouldn’t seem to be of a common type…

          Also I think it’s funny that they say do this in the name of being a good web citizen, but then say send this new mime type down, client’s Accept header value be damned.

          It purports to drive toward “machine-readable” problems but it seems like there’s not much actually actionable and the client has to in practical terms do a bunch of bespoke handling to deal with a backend that is still pretty much open to do whatever they like.

          It has a couple of reasonable seeming examples, but nothing that would make me think “Oh, you implement RFC 9457? Then I already have error handling code ready to go!”

          I’ve seen all sorts of complex errors generated by backends that have all sorts of features like this and more (error messages with parameterized string values, json pointers to specific problematic pieces of the client request. However people just want a human readable response to pass along. I could imagine the example ‘pointer’ being useful to map error details to a client maintained form, but that’s not even the ‘standard’, just a random example ‘extension’…

    • douglasg14b@lemmy.world
      link
      fedilink
      arrow-up
      3
      arrow-down
      3
      ·
      15 hours ago

      Counter argument is that error codes and problem details can be used by attackers to reverse engineer and find exploitable parts of a system.

      Within reason anyways

  • NigelFrobisher@aussie.zone
    link
    fedilink
    arrow-up
    29
    arrow-down
    1
    ·
    edit-2
    2 days ago

    Yep, I’ve got one of these at work now. Technically, 200 can make sense here if you’re using HTTP as RPC transport, as the server relayed the request to its handler and returned the outcome, but damn if it’s not annoying to actually process the response.

    I’ve also seen a lot of devs tie themselves into knots trying to map various execution types to the “semantically correct” HTTP code, but the thing is the abstraction of HTTP is not based around RPC and it’s ultimately a pretty weird fit that we’ve somehow come to view as normal.

  • Rose@slrpnk.net
    link
    fedilink
    arrow-up
    36
    ·
    2 days ago

    Aaagh! Getting some random old person flashbacks.

    Kids. I r-remember a day… You won’t believe this… I got a 404 error page… It was otherwise a normal 404 page with a normal message on it, but it had a giant ad on it… like “while you’re here, how about you buy this stuff”… It was hell… You’ve got no idea how lucky you kids are with uBlock…

  • katy ✨@piefed.blahaj.zone
    link
    fedilink
    English
    arrow-up
    64
    ·
    2 days ago

    error = true with no description or answer is basically ten years of searching stackoverflow and reddit threads for an answer.

    • douglasg14b@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      15 hours ago

      Honestly at this point if it’s source available it’s almost faster to dig through and find the affected module on source to determine behavior.

      Unless of course it’s just crazy abstracted, which can be an unintentional form of obfuscation when applied poorly.

      • katy ✨@piefed.blahaj.zone
        link
        fedilink
        English
        arrow-up
        8
        ·
        1 day ago

        that’s the worst due to how microsoft answers redirects work making it impossible to go back to the previous page.

  • Slotos@feddit.nl
    link
    fedilink
    arrow-up
    22
    arrow-down
    4
    ·
    2 days ago

    JSON API almost always means “not REST”. In other words, it works as intended.

    • JackbyDev@programming.dev
      link
      fedilink
      English
      arrow-up
      7
      ·
      1 day ago

      I don’t wanna be pedantic but most things we call REST aren’t REST. The original definition of REST is what we typically call HATEOAS. So when you say JAON API almost always means not REST you need to qualify that.

      • Slotos@feddit.nl
        link
        fedilink
        arrow-up
        5
        ·
        2 days ago

        However you like, REST doesn’t dictate anything there. Just be consistent and use hypermedia.

        JSON APIs almost never follow REST because they almost never use JSON as hypertext. Worse, no complete stable hypertext JSON standard exists. There’s JSON-HAL, but it lacks a way to represent resource templates (think HTML’s <form>).

        Therefore, with JSON APIs ignoring one of the most basic idea behind REST, why would anyone expect them to follow another idea of REST - consistency?

        REST is a deceptively simple concept. Any time you build an HTML website a human can navigate without consulting documentation, you’re doing it better than vast majority of swagger documented corporate APIs.

        • jj4211@lemmy.world
          link
          fedilink
          arrow-up
          1
          ·
          8 hours ago

          Fun fact, I actually did implement JSON-HAL and peers wondered why I was putting this “silly _links dictionary member” in there.

          I’ll say I’ve seen other REST APIs using json and at least honor the concept of hypermedia, but in a useless way. They’ll have links specified, but even within their API no consistency on what dictionary keys would refer to related resources versus data.

      • tempest@lemmy.ca
        link
        fedilink
        arrow-up
        3
        ·
        2 days ago

        The argument probably goes something like " if you adhere strictly to REST the error codes are all you need" and then metadata can be sent in response headers.

        • Aatube@kbin.melroy.org
          link
          fedilink
          arrow-up
          3
          ·
          2 days ago

          how should a REST API respond to the client sending a URL the ends in a string instead of a numeric ID? like api.social/users/ceeforayteen instead of api.socail/users/11037

          • locuester@lemmy.zip
            link
            fedilink
            English
            arrow-up
            8
            ·
            2 days ago

            I would do a 400 (Bad Request). Then, with varying amounts of detail depending on the scale of the project and the framework capability, the response body would be something like: { “error”:true, “reason”: “validation”, “detail”: “user id should be numeric” }

              • locuester@lemmy.zip
                link
                fedilink
                English
                arrow-up
                3
                ·
                edit-2
                19 hours ago

                A RESTful service is (usually as of today) a JSON API. They aren’t mutually exclusive things.

                There’s no black and white definition there.

                However, when someone is creating a RESTful service, they’re stating that they’ll be paying mind to HTTP Verbs and status codes as a fundamental part of their design.

                In the original image posted, that dev clearly wasn’t paying mind to the HTTP layer and as such a commenter called it just a “JSON API”, which is the catchall, ugly, Wild West, typical way of doing things (always return 200, errors are in the json).

                Once again tho, it’s not black and white. Others can and will disagree and want to be pedantic. I’ve been a professional dev for 35 years, devs love to argue abt this shit.

                • luciferofastora@feddit.org
                  link
                  fedilink
                  arrow-up
                  1
                  ·
                  6 hours ago

                  devs love to argue abt this shit

                  Devs and standards have a contentious relationship.

                  If I develop something, I obviously know what works best for me, so I don’t want to be constrained by some dumb standard. If someone else doesn’t follow them and it makes things harder for me, they’re a clueless fuckwit that shouldn’t be allowed near a computer ever again.

                  Yes, that’s a double standard: I don’t even have a standard when it comes to handling standards.

                • 0x0@lemmy.zip
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  13 hours ago

                  devs love to argue abt this shit.

                  Tabs vs spaces comes to mind.

          • tempest@lemmy.ca
            link
            fedilink
            arrow-up
            3
            ·
            2 days ago

            Depends on the verb and the application. If the string is valid 200, if it isn’t 400, 404.

    • porkloin@lemmy.world
      link
      fedilink
      arrow-up
      7
      arrow-down
      2
      ·
      2 days ago

      That’s true, but for a good reason. GraphQL is transport agnostic, so using HTTP status to represent errors doesn’t make sense. HTTP is just a carrier for GraphQL, and the status code represents whether or not the HTTP part was successful.

      • The_Decryptor@aussie.zone
        link
        fedilink
        English
        arrow-up
        2
        ·
        19 hours ago

        Well no, the HTTP error codes are about the entire request, not just whether or not the actual header part was received and processed right.

        Like HTTP 403, HTTP only has a basic form of authentication built in, anything else needs the server to handle it externally (e.g. via session cookies). It wouldn’t make sense to send “HTTP 200” in response to trying to access a resource without being logged in just because the request was well formed.

        • porkloin@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          18 hours ago

          Many GraphQL and gRPC APIs do exactly that and return HTTP 200 even if the request didn’t auth.

          Just because you are heavily biased toward using HTTP status for application layer errors doesn’t make it right. It is so wildly common that people can’t imagine it working another way, and I get that.

          But it’s not “wrong” to do application layer auth status codes and apply no transport layer auth status codes It’s just a different paradigm than most devs are used to.

          • jj4211@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            8 hours ago

            Think the point would be that it’s super easy to also set a ‘non-ok’ status in HTTP. Sure it may be insufficient for sophisticated handling, but at least you can get a vague sense of ‘something went wrong’…

            Sure have your more specific API specific error code and your error details in the body, but at least toss a generic ‘500’ into the status code. I often find myself writing client software where I don’t need specific handling I just need to know ‘it failed’, and it’s obnoxious to deal with these interfaces where I have to sweat multiple potential ways for it to report failures when I just don’t care about the specifics. Sometimes an API doesn’t even have a consistent place that it sticks it’s return code, some don’t even define a reasonable way to know ‘failure’ and require you to explicitly map a huge number of ‘info’ to ascertain if it’s normal or error type state.

          • The_Decryptor@aussie.zone
            link
            fedilink
            English
            arrow-up
            3
            ·
            13 hours ago

            Ehh, that really feel like “But other people do it wrong too” to me, half the 4xx error codes are application layer errors for example (404 ain’t a transport layer error, neither is 403, 415, 422 or 451)

            It also complicates actually processing the request as you’ve got to duplicate error handling between “request failed” and “request succeeded but actually failed”. My local cinema actually hits that error where their web frontend expects the backend to return errors, but the backend lies and says everything was successful, and then certain things break in the UI.

            • luciferofastora@feddit.org
              link
              fedilink
              arrow-up
              1
              ·
              6 hours ago

              frontend expects the backend to return errors, but the backend lies and says everything was successful, and then certain things break in the UI

              That’s a double failure then: not only does the backend do it wrong, the frontend devs don’t even know it. If they’d agreed on one way of handling it, they’d still be able to work it out. But if the devs don’t even communicate their standards with each other and the frontend devs obviously don’t know about the problem…

      • Olap@lemmy.world
        link
        fedilink
        arrow-up
        6
        ·
        2 days ago

        If only that were true. They are intimately connected and to pretend otherwise is laughable to me

        • porkloin@lemmy.world
          link
          fedilink
          arrow-up
          7
          ·
          1 day ago

          What do you mean? You can literally run GraphQL without HTTP. This isn’t just a GraphQL-ism, gRPC also does it https://grpc.io/docs/guides/status-codes/

          I understand that most people use GraphQL over HTTP and that from a developer perspective you’d rather have HTTP status codes like every other REST API. To which I’d say, why don’t you just use REST instead?

          There are a bunch of legitimate reasons why a clean separation of transport layer and application layer makes sense - you just aren’t using them so it feels like an arbitrary frustration to you.

          Have you ever run an application like a golang REST API behind an envoy or nginx proxy or load balancer and gotten an HTTP status 500 back and wrongly assumed it was coming from your application/golang code, only to later find it was a problem at the proxy or load balancer? If so, you’ve experienced the misdirection of combining transport and application layer being forced to share a status field. This isn’t a trivial example - time is wasted every day by developers misdiagnosing errors originating from transport as application errors, and vice versa.

          You might not like it, but separating them IS smart design.

          • jj4211@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            2 hours ago

            misdiagnosing errors originating from transport as application errors, and vice versa.

            Shouldn’t the response body disambiguaite clearly whose fault it is? I mean you have to anyway if you advocate for ‘200 for everything’. You still have that same response body whether the HTTP status code is 200 or 500.

            We honor the status code while providing an error body and it’s always blatantly obvious whether it’s an infrastructure issue or “true backend” issue when we see an issue. In my team I can’t recall anyone ever getting confused for even a little bit about whether an observed anomaly was web infrastructure or the backend, despite us setting HTTP status codes to error when, you know, we see an error.

          • Olap@lemmy.world
            link
            fedilink
            arrow-up
            3
            arrow-down
            1
            ·
            1 day ago

            Logs, logs, logs, you’ll pour over logs anyway. Hands up anyone who has run GraphQL over anything but http? Won’t be many. And then another show of hands please: who’s written a basic request using http tooling instead? Bet there’s tons!

            They threw away loads of tooling for the sake of vanity imo