Urgent.News

What's breaking now, across thousands of outlets.

Tech

Meilleures pratiques de gestion des erreurs des API REST : Codes d'état, RFC 9457 et erreurs réessayables

Concevoir un contrat d’erreur robuste pour une API REST Les réponses d’erreur de votre API font partie de son contrat. Les clients les analysent, les mécanismes de réessai s’appuient sur elles et les équipes support les consultent à 2 heures du matin. Pourtant, beaucoup d’équipes détaillent le chemin nominal et laissent les erreurs dépendre des valeurs par défaut du framework. Résultat :…

Designing a robust error contract for a REST API is crucial, as error responses form an integral part of the contract. Clients analyze these errors, retry mechanisms rely on them, and support teams consult them during late-night hours. However, many teams document the normal path while leaving errors to default framework values. As a result, an API may contain multiple error formats, a 200 response with success: false, or even a stack trace revealing the database schema.

This guide presents a comprehensive approach from start to finish, covering the selection of the appropriate HTTP code, standardizing the error body using Problem Details from RFC 9457, separating machine codes from human messages, indicating whether an error is retryable, and preventing any sensitive information leakage. It also demonstrates how to test each failure path in Apidog.

Start with the HTTP status code, not the HTTP body. The body already provides a first layer of semantics. RFC 9110 defines families of HTTP status codes, such as 4xx (client errors), which will generally fail again with the same request, and 5xx (server or dependency errors), where the client's request may be valid. Generic clients, proxies, caches, and retry libraries use these codes without reading your JSON. Consult the MDN reference for HTTP status codes and apply a consistent convention.

Use the correct code for the situation. Do not use it incorrectly, as it can reveal sensitive information. For example, use 400 Bad Request for invalid JSON, incorrect content type, or missing required fields, and 422 Unprocessable Content when the request is valid but business rules are violated, such as negative amounts or unsupported currencies.

Use 401 Unauthorized when the client has not proven its identity, and 403 Forbidden when the identity is known but access is denied. Respond with WWW-Authenticate in the latter case. Use 403 Forbidden when the client has valid credentials but lacks sufficient permissions. Use 404 Not Found when the resource does not exist, or when confirmation of its existence is not authorized.

Use 410 Gone when the resource has been deleted permanently. Indicate retryability and prevent information leakage.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

API Tekrar Deneme Mantığı ve Üstel Geri Çekilme: Gerçekten İşe Yarayan Desenler

Ödeme API çağrınız sabah 2'de başarısız oldu. Bu bir ağ arızası mıydı, hız sınırı mıydı, yoksa çökmüş bir sunucu mu? Cevap, yeniden denemenin işlemi kurtarıp kurtarmayacağını veya müşteriyi iki kez…

  • Idempotans POST isteklerinde sıfır tekrarlarını sağlar
  • Üstel geri çekilme, gecikmeyi yükselterek senkronizasyonu önler
  • Retry-After başlığı, belirli bekleme sürelerini istemcilerine bildirir

Study: Blue light impairs visual acuity!

Chromatic Aberration and Retinal Sensitivity: Analyzing the Impact of Short-Wavelength Light on Visual Acuity The human visual system is a biological transducer optimized for evolutionary environments…

  • Blue light causes chromatic aberration and retinal scatter
  • Blue light focuses in front of retina, red behind it
  • LED displays require adjustments to maintain visual acuity

bibliograph: An AppView for interfacing with bibliographic information on ATProto

An ATProto AppView that provides information about books for other apps to build on top of. First user of it is https://livtet.olamaelcu.net/ Comments

  • Bibliograph is an open-source appview for ATProto bibliographic info
  • Uses methods like book review search and TAP ingestion for discovery
  • Prometheus monitoring available at http://localhost:9090 with 7-day TSDB

More from Monday 31 August →