Code Explainers
Code explainers tagged #error-handling
ruby
require "nokogiri" require "open-uri" require "set"
Extracting and normalizing links in Ruby
web-scraping
url-parsing
html-parsing
Intermediate
8 steps
go
package handlers import ( "context"
A custom Gin validator backed by Redis
validation
redis
struct-tags
Intermediate
8 steps
rust
use std::collections::BTreeSet; #[derive(Debug)] pub enum FieldError {
Parsing a cron field in Rust
parsing
error-handling
enums
Intermediate
7 steps
rust
use hmac::{Hmac, Mac}; use sha2::Sha256; use subtle::ConstantTimeEq;
HMAC signing and constant-time verify in Rust
hmac
cryptography
constant-time
Intermediate
7 steps
ruby
class WeatherLookup Result = Struct.new(:temperature, :conditions, keyword_init: true) class TimeoutError < StandardError; end
A resilient weather API service object in Rails
service-object
http-client
error-handling
Intermediate
7 steps
ruby
namespace :active_storage do desc "Purge blobs that have been unattached for more than 48 hours" task purge_stale: :environment do cutoff = 48.hours.ago
A Rake task to purge stale Active Storage blobs in Rails
rake
active-storage
batch-processing
Intermediate
8 steps
javascript
class ProblemError extends Error { constructor(status, title, detail, extensions = {}) { super(detail || title); this.status = status;
RFC 7807 problem details in Express
error-handling
middleware
http-api
Intermediate
8 steps
go
type Warning struct { Field string `json:"field"` Code string `json:"code"` Message string `json:"message"`
Partial-success responses in Gin
error-handling
input-validation
http-status
Intermediate
8 steps
php
<?php namespace App\Http\Controllers;
Building a health check endpoint in Laravel
health-check
invokable-controller
error-handling
Intermediate
8 steps
typescript
type RetryableRequest<T> = () => Promise<T>; interface RetryOptions { maxAttempts?: number;
Retrying HTTP requests with backoff
retry
exponential-backoff
error-handling
Intermediate
8 steps
javascript
const express = require('express'); const createError = require('http-errors'); const { Article } = require('../models');
Sharing route logic with router.param in Express
middleware
authorization
dry
Intermediate
10 steps
python
from fastapi import APIRouter, status from fastapi.responses import JSONResponse from sqlalchemy import text from sqlalchemy.exc import SQLAlchemyError
Liveness vs readiness health checks in FastAPI
health-checks
dependency-injection
async
Intermediate
6 steps
typescript
import { Component, inject } from '@angular/core'; import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms'; import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { finalize } from 'rxjs';
A reactive signup form in Angular
reactive-forms
validation
dependency-injection
Intermediate
10 steps
go
package config import ( "bufio"
Parsing INI files in Go
parsing
state-machine
error-handling
Intermediate
7 steps
rust
use axum::{ async_trait, extract::FromRequestParts, http::{header::HeaderName, request::Parts, StatusCode},
A custom tenant extractor in Axum
extractors
middleware
error-handling
Intermediate
7 steps
rust
use axum::{ extract::{FromRef, FromRequestParts}, http::{header, request::Parts, StatusCode}, RequestPartsExt,
How a JWT extractor works in Axum
jwt
authentication
extractors
Intermediate
8 steps
rust
#[derive(Deserialize)] pub struct CreateArticle { title: String, body: String,
Building a create endpoint in Axum
extractors
json-deserialization
sqlx
Intermediate
7 steps
go
func UploadDocument(c *gin.Context) { fileHeader, err := c.FormFile("file") if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": "file is required"})
Handling multipart uploads in Gin
multipart-upload
validation
error-handling
Intermediate
9 steps