salvo-error-handling

Map Salvo handler errors to standardized HTTP responses with JSON payloads.

1|Updated Mar 16, 2024
One-click install
npx skills add https://github.com/tdcare/genies --skill salvo-error-handling-tdcare
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: salvo-error-handling
Source: https://github.com/tdcare/genies/tree/main/.qoder/skills/salvo-error-handling
Command: npx skills add https://github.com/tdcare/genies --skill salvo-error-handling-tdcare

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Building robust Salvo-based APIs requires consistent error reporting, safe handling of business and system failures, and resilient responses to panics. This skill provides a structured approach to map errors into HTTP status codes, provide clear JSON error payloads, and centralize error-related concerns.

Core Features & Use Cases

  • Status-based mapping: Convert business errors, validation issues, and server faults into appropriate 4xx/5xx responses with meaningful messages.
  • Custom error types & JSON APIs: Define Writer/thiserror patterns to produce uniform error payloads and reduce leakage of internal details.
  • Panic safety & logging: Use CatchPanic and logging to catch panics, log context, and return safe responses.
  • Use Case: Build reliable APIs that fail gracefully under invalid input, missing resources, or database outages.

Quick Start

Integrate StatusError with your Salvo routes to return consistent JSON errors for 4xx/5xx responses.

Frequently Asked Questions about salvo-error-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I return consistent JSON error responses from a Salvo API?

To return consistent JSON error responses from a Salvo API, map handler errors to standardized HTTP status codes using StatusError. This centralizes error reporting and ensures uniform JSON payloads for 4xx and 5xx responses.

What is the best way to handle panics in Rust Salvo web services?

The best way to handle panics in Salvo web services is using CatchPanic to gracefully recover from panics. Combined with logging, it catches failures, logs context, and returns safe responses without crashing the server.

How do I map custom Rust error types to HTTP status codes in Salvo?

You can map custom Rust error types to HTTP status codes in Salvo by defining Writer and thiserror patterns. This approach produces uniform error payloads and prevents the leakage of internal system details to clients.

Does Salvo support centralized error handling for validation and database outages?

Yes, Salvo supports centralized error handling for validation and database outages by converting business errors and server faults into appropriate 4xx/5xx responses. This allows APIs to fail gracefully under missing resources.

How do I prevent leaking internal Rust error details in Salvo HTTP responses?

Prevent leaking internal Rust error details in Salvo HTTP responses by implementing custom error types with the Writer pattern. This ensures safe, standardized JSON error payloads are returned instead of raw internal fault messages.