Code Explainers
Code explainers tagged #error handling
go
func (h *ArticleHandler) Create(c *gin.Context) { var req struct { Title string `json:"title" binding:"required"` Body string `json:"body" binding:"required"`
Handling a POST request in Gin
request binding
validation
http status codes
Intermediate
7 steps
go
package middleware import ( "errors"
Capping request body size in Gin
middleware
request limits
error handling
Intermediate
5 steps
ruby
class PaymentGateway class MissingCredentialError < StandardError; end def initialize(env: Rails.env)
Wrapping Rails credentials in a gateway
encapsulation
credentials
error handling
Intermediate
6 steps
python
from urllib.parse import urlparse, parse_qs from dataclasses import dataclass, field ALLOWED_SCHEMES = {"http", "https"}
Validating URLs into a safe endpoint in Python
input validation
url parsing
dataclasses
Intermediate
7 steps
go
func ServeVideo(c *gin.Context) { id := c.Param("id") video, err := videoRepo.FindByID(c.Request.Context(), id) if err != nil {
Streaming video files with Gin
http streaming
range requests
file serving
Intermediate
6 steps
go
package dateutil import ( "fmt"
Parsing and formatting dates in Go
date parsing
layouts
timezones
Intermediate
7 steps
typescript
import { Injectable, NestInterceptor, ExecutionContext,
A per-route timeout interceptor in NestJS
interceptors
metadata reflection
rxjs
Intermediate
8 steps
go
package handlers import ( "errors"
Turning Gin binding errors into field messages
input validation
struct tags
error handling
Intermediate
9 steps
go
package handlers type BookURI struct { Collection string `uri:"collection" binding:"required,alphanum"`
Validating URI params in a Gin handler
input validation
struct binding
error handling
Intermediate
7 steps
php
<?php namespace App\Services\Provisioning;
Sequencing site setup with Laravel job chains
job chains
queues
async workflows
Intermediate
6 steps
go
package handlers import ( "fmt"
Handling multipart profile uploads in Gin
form binding
file upload
validation
Intermediate
7 steps
ruby
class Webhooks::StripeController < ApplicationController skip_before_action :verify_authenticity_token skip_before_action :authenticate_user!
How a Rails Stripe webhook controller works
webhooks
signature verification
event dispatch
Intermediate
7 steps
rust
use axum::{ body::Body, extract::Request, http::{header, StatusCode},
How bearer-auth middleware works in Axum
middleware
authentication
request extensions
Intermediate
7 steps
go
package config import ( "encoding/json"
Parsing untyped JSON config in Go
json parsing
type assertions
error handling
Intermediate
7 steps
ruby
class FundsTransfer class InsufficientFundsError < StandardError; end def initialize(source:, destination:, amount:)
Atomic money transfers with Rails transactions
service object
database transactions
row locking
Advanced
9 steps
javascript
const express = require('express'); const v1 = express.Router();
Versioning an API with Express Routers
api versioning
routing
modularity
Intermediate
10 steps
go
package handlers type SignupRequest struct { Email string `json:"email" binding:"required,email"`
Validated signup handler in Gin
request validation
error handling
http status codes
Intermediate
7 steps
ruby
class CheckoutService Result = Struct.new(:success?, :order, :error, keyword_init: true) def self.call(...)
How a Rails checkout service object works
service object
transactions
result object
Intermediate
9 steps