Code Explainers

Code explainers tagged #error-handling

rust
use std::fmt;
 
#[derive(Debug)]
pub enum ConfigError {

Building a custom error type in Rust

error-handling enums trait-implementation
Intermediate 9 steps
rust
use axum::{
    async_trait,
    extract::{rejection::JsonRejection, FromRequest, Request},
    http::StatusCode,

A validating JSON extractor in Axum

extractors validation error-handling
Intermediate 7 steps
python
import os
import uuid
 
from flask import Blueprint, current_app, jsonify, request

Handling secure file uploads in Flask

file-upload validation blueprints
Intermediate 8 steps
java
package com.example.orders.messaging;
 
import com.example.orders.dto.OrderEvent;
import com.example.orders.service.OrderProcessingService;

Manual RabbitMQ acks in a Spring listener

message-queue error-handling acknowledgement
Intermediate 6 steps
rust
use axum::{extract::{Query, State}, http::StatusCode, Json};
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;

Cursor pagination in an Axum handler

cursor-pagination keyset-pagination base64
Advanced 10 steps
rust
use std::num::ParseIntError;
 
fn parse_line(line: &str) -> Result<Vec<i64>, ParseIntError> {
    line.split(',')

Collecting Results in Rust iterators

iterators error-handling result
Intermediate 7 steps
ruby
module Api
  module V1
    class BaseController < ActionController::API
      rescue_from StandardError, with: :render_internal_error

Centralized API error handling in Rails

error-handling rescue-from json-api
Intermediate 7 steps
javascript
import { parsePhoneNumberFromString } from 'libphonenumber-js';
 
export class PhoneValidationError extends Error {
  constructor(message, code) {

Normalizing phone numbers with typed errors

validation error-handling custom-errors
Intermediate 6 steps
typescript
import { Injectable, computed, inject, signal } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { firstValueFrom } from 'rxjs';
 

Optimistic updates with Angular signals

signals optimistic-updates state-management
Intermediate 9 steps
python
import os
from datetime import datetime, timezone
 
import jwt

JWT bearer auth as a FastAPI dependency

authentication jwt dependency-injection
Intermediate 7 steps
rust
use std::error::Error;
use std::path::Path;
 
use serde::Deserialize;

Custom CSV deserialization with serde in Rust

serde csv deserialization
Intermediate 7 steps
go
package config
 
import (
	"fmt"

Loading typed config from environment variables in Go

configuration environment-variables type-parsing
Beginner 8 steps
python
import logging
import traceback
 
from flask import Blueprint, jsonify, request

Centralized JSON error handling in Flask

error-handling blueprints json-api
Intermediate 5 steps
rust
use std::time::Duration;
 
use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use serde::Serialize;

A timeout-guarded health check in Axum

health-check timeout error-handling
Intermediate 6 steps
php
<?php
 
final class OrderRepository
{

Atomic order placement with PDO transactions

transactions prepared-statements atomicity
Intermediate 8 steps
php
<?php
 
function uploadDocument(string $endpoint, string $filePath, array $meta): array
{

Uploading a file with cURL in PHP

curl file-upload http
Intermediate 8 steps
typescript
type Event = Record<string, unknown>;
 
interface BatcherOptions {
  endpoint: string;

Batching analytics events in TypeScript

batching buffering async
Intermediate 8 steps
javascript
const logger = require('./logger');
 
class AppError extends Error {
  constructor(message, statusCode = 500, details = null) {

Centralized error handling in Express

error-handling middleware custom-errors
Intermediate 8 steps