Code Explainers

Code explainers tagged #error-handling

php
<?php
 
declare(strict_types=1);
 

Validating registration input with filter_var

validation sanitization filter_var
Intermediate 8 steps
rust
use axum::{
    http::StatusCode,
    response::{IntoResponse, Response},
    Json,

How a custom error type maps to HTTP in Axum

error-handling enums trait-implementation
Intermediate 7 steps
java
@Service
public class GitHubClient {
 
    private final WebClient webClient;

Calling the GitHub API with Spring WebClient

reactive http-client dependency-injection
Intermediate 7 steps
go
package main
 
import (
	"errors"

Parsing and validating CLI flags in Go

cli-parsing validation error-handling
Intermediate 8 steps
java
public class ThumbnailProcessor {
 
    private static final int MAX_CONCURRENCY = 4;
 

Bounded parallel thumbnail rendering in Java

concurrency thread-pool futures
Intermediate 7 steps
php
<?php
 
namespace App\Rules;
 

How a custom phone validation rule works in Laravel

validation custom-rules dependency
Intermediate 6 steps
rust
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
 

Building a typed create_user handler in Axum

serde extractors sqlx
Intermediate 7 steps
go
package store
 
import (
	"database/sql"

Wrapping and inspecting errors in Go

error-handling error-wrapping sentinel-errors
Intermediate 8 steps
javascript
async function fetchAllPages(baseUrl, { pageSize = 100, headers = {} } = {}) {
  const results = [];
  let cursor = null;
 

Cursor-based pagination with fetch

pagination async-await fetch
Intermediate 6 steps
rust
use std::error::Error;
use std::fmt;
 
#[derive(Debug)]

Building a typed error enum in Rust

error-handling enums trait-implementation
Intermediate 9 steps
python
import random
import time
import logging
from functools import wraps

A retry decorator with exponential backoff

decorators retry exponential-backoff
Intermediate 6 steps
rust
use std::fs::File;
use std::io::{self, BufRead, BufReader};
use std::path::Path;
 

Buffered log scanning in Rust

buffered-io error-handling streaming
Intermediate 9 steps
go
package middleware
 
import (
	"errors"

Centralized error handling in Gin

middleware error-handling custom-errors
Intermediate 8 steps
python
import os
import tempfile
from pathlib import Path
from typing import Union

How atomic file writes work in Python

atomicity filesystem durability
Advanced 7 steps
rust
use axum::{
    extract::FromRequestParts,
    http::{request::Parts, StatusCode, header::AUTHORIZATION},
};

How a JWT extractor works in Axum

authentication jwt extractors
Intermediate 8 steps
go
package main
 
import (
	"bufio"

Counting matching lines in Go with bufio

file-io buffered-scanning error-handling
Intermediate 4 steps
rust
use axum::{extract::Form, http::StatusCode, response::{IntoResponse, Response}, Json};
use serde::Deserialize;
use serde_json::json;
use std::collections::HashMap;

Validating a signup form in Axum

form-validation deserialization error-handling
Intermediate 8 steps
javascript
const fs = require('fs');
const path = require('path');
 
router.get('/downloads/:name', (req, res, next) => {

Streaming file downloads in Express

streaming backpressure file-download
Advanced 9 steps