Code Explainers

Code explainers tagged #error-handling

java
package com.example.validation;
 
import java.util.List;
import java.util.stream.Collectors;

Validating JSON payloads against a schema in Java

json-schema validation recursion
Intermediate 8 steps
go
func (h *ExportHandler) BulkExport(c *gin.Context) {
	projectID := c.Param("projectID")
 
	reports, err := h.reports.ListByProject(c.Request.Context(), projectID)

Streaming a ZIP download in Gin

streaming zip-archive http-headers
Intermediate 8 steps
go
package email
 
import (
	"errors"

Normalizing and deduping email addresses in Go

validation normalization deduplication
Intermediate 8 steps
javascript
const express = require('express');
const multer = require('multer');
const path = require('path');
const crypto = require('crypto');

Safe image uploads with Multer in Express

file-upload multer validation
Intermediate 7 steps
rust
use std::collections::VecDeque;
 
#[derive(Debug)]
pub struct Hunk {

Applying a diff hunk in Rust

enums error-handling pattern-matching
Intermediate 8 steps
java
@Configuration
public class OrderConsumerConfig {
 
    @Bean

Wiring a resilient Kafka consumer in Spring

kafka deserialization error-handling
Intermediate 8 steps
rust
use axum::{
    body::Body,
    http::{Method, StatusCode, Uri},
    response::{IntoResponse, Response},

Nesting routers and JSON fallbacks in Axum

routing http json-responses
Intermediate 7 steps
java
@Configuration
@EnableKafka
public class KafkaErrorHandlingConfig {
 

Kafka retry and dead-letter handling in Spring

kafka error-handling retry
Intermediate 7 steps
go
package batch
 
import "fmt"
 

Splitting a slice into batches in Go

generics slices error-handling
Intermediate 6 steps
php
<?php
 
namespace App\Console\Commands;
 

How a database backup command works in Laravel

artisan-command shell-process error-handling
Intermediate 8 steps
typescript
import { Controller } from '@nestjs/common';
import {
  MessagePattern,
  Payload,

Manual RabbitMQ acks in a NestJS controller

microservices message-queue acknowledgement
Intermediate 8 steps
rust
use std::convert::TryFrom;
 
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum HttpStatus {

Converting HTTP codes with TryFrom in Rust

enums error-handling trait-implementation
Intermediate 8 steps
rust
use chrono::NaiveDate;
use serde::{Deserialize, Deserializer};
 
#[derive(Debug, Deserialize)]

Custom date parsing with serde in Rust

serde deserialization csv-parsing
Intermediate 7 steps
python
import uuid
from pathlib import Path
 
from fastapi import APIRouter, File, Form, HTTPException, UploadFile

Handling multipart file uploads in FastAPI

file-upload validation multipart-form
Intermediate 6 steps
rust
use axum::{extract::State, http::StatusCode, Json};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use uuid::Uuid;

An atomic money transfer handler in Axum

database-transactions atomicity error-handling
Intermediate 9 steps
typescript
import { Injectable, NotFoundException, ConflictException } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, DeepPartial } from 'typeorm';
import { User } from './entities/user.entity';

Building a CRUD service in NestJS

crud dependency-injection repository-pattern
Intermediate 7 steps
php
<?php
 
namespace App\Queue;
 

A stable priority job queue in PHP

priority-queue data-structures closures
Intermediate 8 steps
typescript
import { Controller, Get, Param, Query, Redirect, NotFoundException } from '@nestjs/common';
import { LinksService } from './links.service';
 
@Controller('links')

Handling HTTP redirects in NestJS

redirects routing decorators
Intermediate 7 steps