Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Error’d: Pickup Sticklers

      September 27, 2025

      From Prompt To Partner: Designing Your Custom AI Assistant

      September 27, 2025

      Microsoft unveils reimagined Marketplace for cloud solutions, AI apps, and more

      September 27, 2025

      Design Dialects: Breaking the Rules, Not the System

      September 27, 2025

      Building personal apps with open source and AI

      September 12, 2025

      What Can We Actually Do With corner-shape?

      September 12, 2025

      Craft, Clarity, and Care: The Story and Work of Mengchu Yao

      September 12, 2025

      Cailabs secures €57M to accelerate growth and industrial scale-up

      September 12, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Using phpinfo() to Debug Common and Not-so-Common PHP Errors and Warnings

      September 28, 2025
      Recent

      Using phpinfo() to Debug Common and Not-so-Common PHP Errors and Warnings

      September 28, 2025

      Mastering PHP File Uploads: A Guide to php.ini Settings and Code Examples

      September 28, 2025

      The first browser with JavaScript landed 30 years ago

      September 27, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured
      Recent
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: I Am Not 200

    CodeSOD: I Am Not 200

    August 19, 2025

    In theory, HTTP status codes should be easy to work with. In the 100s? You’re doing some weird stuff and breaking up large requests into multiple sub-requests. 200s? It’s all good. 300s? Look over there. 400s? What the hell are you trying to do? 500s? What the hell is the server trying to do?

    This doesn’t mean people don’t endlessly find ways to make it hard. LinkedIn, for example, apparently likes to send 999s if you try and view a page without being logged in. Shopify has invented a few. Apache has added a 218 “This is Fine“. And then there’s WebDAV, which not only adds new status codes, but adds a whole bunch of new verbs to HTTP requests.

    Francesco D sends us a “clever” attempt at handling status codes.

        <span class="hljs-keyword">try</span> {
          HttpRequest.<span class="hljs-type">Builder</span> <span class="hljs-variable">localVarRequestBuilder</span> <span class="hljs-operator">=</span> {{operationId}}RequestBuilder({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}headers);
          <span class="hljs-keyword">return</span> memberVarHttpClient.sendAsync(
              localVarRequestBuilder.build(),
              HttpResponse.BodyHandlers.ofString()).thenComposeAsync(localVarResponse -> {
                <span class="hljs-keyword">if</span> (localVarResponse.statusCode()/ <span class="hljs-number">100</span> != <span class="hljs-number">2</span>) {
                  <span class="hljs-keyword">return</span> CompletableFuture.failedFuture(getApiException(<span class="hljs-string">"{{operationId}}"</span>, localVarResponse));
                }
                {{#returnType}}
                <span class="hljs-keyword">try</span> {
                  <span class="hljs-type">String</span> <span class="hljs-variable">responseBody</span> <span class="hljs-operator">=</span> localVarResponse.body();
                  <span class="hljs-keyword">return</span> CompletableFuture.completedFuture(
                      responseBody == <span class="hljs-literal">null</span> || responseBody.isBlank() ? <span class="hljs-literal">null</span> : memberVarObjectMapper.readValue(responseBody, <span class="hljs-keyword">new</span> <span class="hljs-title class_">TypeReference</span><{{{returnType}}}>() {})
                  );
                } <span class="hljs-keyword">catch</span> (IOException e) {
                  <span class="hljs-keyword">return</span> CompletableFuture.failedFuture(<span class="hljs-keyword">new</span> <span class="hljs-title class_">ApiException</span>(e));
                }
                {{/returnType}}
                {{^returnType}}
                <span class="hljs-keyword">return</span> CompletableFuture.completedFuture(<span class="hljs-literal">null</span>);
                {{/returnType}}
          });
        }
    

    Okay, before we get to the status code nonsense, I first have to whine about this templating language. I’m generally of the mind that generated code is a sign of bad abstractions, especially if we’re talking about using a text templating engine, like this. I’m fine with hygienic macros, and even C++’s templating system for code generation, because they exist within the language. But fine, that’s just my “ok boomer” opinion, so let’s get into the real meat of it, which is this line:

    localVarResponse.statusCode()/ <span class="hljs-number">100</span> != <span class="hljs-number">2</span>
    

    “Hey,” some developer said, “since success is in the 200 range, I’ll just divide by 100, and check if it’s a 2, helpfully truncating the details.” Which is fine and good, except neither 100s nor 300s represent a true error, especially because if the local client is doing caching, a 304 tells us that we can used the cached version.

    For Francesco, treating 300s as an error created a slew of failed requests which shouldn’t have failed. It wasn’t too difficult to detect- they were at least logging the entire response- but it was frustrating, if only because it seems like someone was more interested in being clever with math than actually writing good software.

    [Advertisement]
    Keep all your packages and Docker containers in one place, scan for vulnerabilities, and control who can access different feeds. ProGet installs in minutes and has a powerful free version with a lot of great features that you can upgrade when ready.Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleSentry Adds Logs Support for Laravel Apps
    Next Article IT Leader’s Guide to IT Service Management

    Related Posts

    News & Updates

    Building personal apps with open source and AI

    September 12, 2025
    News & Updates

    What Can We Actually Do With corner-shape?

    September 12, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    How to Assign Unique IDs to Express API Requests for Tracing

    Development

    GitHub launches MCP Registry to provide central location for trusted servers

    Tech & Work

    Bulma CSS Framework

    Web Development

    Critical Flaw in Apache Parquet Allows Remote Attackers to Execute Arbitrary Code

    Development

    Highlights

    The History of Themeable User Interfaces

    September 4, 2025

    Design tokens may be the latest incarnation, but software creators have been creating themeable user interfaces…

    Linux has over 6% of the desktop market? Yes, you read that right – here’s how

    July 17, 2025

    CodeSOD: A Unique Way to Primary Key

    July 22, 2025

    DDoS Attack Hits Adyen, Causing Transaction Failures in EU

    April 24, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.