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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 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

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Customize the Truncation of HTTP Client Request Exceptions

    Customize the Truncation of HTTP Client Request Exceptions

    December 20, 2024

    Customize the Truncation of HTTP Client Request Exceptions

    Have you ever received a bug report or looked in Sentry only to find a truncated HTTP client exception you couldn’t read? By default, HTTP responses are truncated, which could potentially leave off important clues as to why a request failed or what happened:

    HTTP request returned status code 422:
    {"error":{"code":422,"message":"The Request can not be completed because the provided request contains invalid data. Key at 'cus (truncated...)
    

    Starting in Laravel 11.35, you can now control this behavior with two new convenience methods that you can add to your application’s bootstrap/app.php file:

    // bootstrap/app.php
     
    use IlluminateHttpClientRequestException;
     
    return Application::configure(basePath: dirname(__DIR__))
        // ...
        ->withExceptions(function (Exceptions $exceptions) {
            $exceptions->dontTruncateRequestExceptions();
     
            // Or ...
     
            $exceptions->truncateRequestExceptionsAt(260);
        })->create();
    

    When an HTTP client exception happens, it will not be truncated anymore, or if you still want truncation, you can control the length of truncation to make it longer than the original. Of course, you can still catch HTTP client exceptions and report anything about the exception that you want:

    try {
        $response = Http::throws()->get('https://api.example.com/some-error');
    
        // ...
    } catch (IlluminateHttpClientRequestException $e) {
        Log::error('HTTP Error', [
            // The message will be truncated (or not) based on your setting.
            'message' => $e->getMessage(),
            'response' => $e->response->json(),
            'status' => $e->response->status(),
            // ...
        ]);
    }
    

    You can learn more about working with exceptions in Laravel’s HTTP client from the Laravel documentation, which includes all the conditional error handling and truncation docs.

    A shoutout to Steve Bauman for making this possible in Pull Request #53734 as part of Laravel 11.35.0!


    The post Customize the Truncation of HTTP Client Request Exceptions appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest
    Laravel articles like this directly in your inbox.

    Source: Read More 

    Hostinger
    Facebook Twitter Reddit Email Copy Link
    Previous ArticleWirechat – Laravel Livewire chat package
    Next Article Using withoutWrapping to flatten API responses

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-40906 – MongoDB BSON Serialization BSON::XS Multiple Vulnerabilities

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    CVE-2025-46749 – Apache Struts XSS

    Common Vulnerabilities and Exposures (CVEs)

    Beginners Guide to The Gemini LLM

    Artificial Intelligence

    FakeBat Loader Malware Spreads Widely Through Drive-by Download Attacks

    Development

    AI Prompt Engineering for Cybersecurity: The Details Matter

    Development
    GetResponse

    Highlights

    News & Updates

    Verdansk is coming back to Call of Duty: Warzone, and I’m pretty sure I know which weapon EVERYONE will be putting in their loadouts

    April 3, 2025

    Call of Duty has brought back the Kilo 141 alongside the returning Verdansk map, and…

    CVE-2025-3491 – WordPress Add Custom Page Template PHP Code Injection

    April 26, 2025

    This AI Paper Introduces HalluVault for Detecting Fact-Conflicting Hallucinations in Large Language Models

    May 9, 2024

    The Xbox handheld is actually a next-gen ROG Ally — It’s the best hardware crossover I could hope for

    March 31, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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