add-error-type
Add a new custom error type for domain-specific errors. Use when creating errors for specific business rules or HTTP status codes. Triggers on "add error", "custom error", "error type".
Best use case
add-error-type is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Add a new custom error type for domain-specific errors. Use when creating errors for specific business rules or HTTP status codes. Triggers on "add error", "custom error", "error type".
Teams using add-error-type should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/add-error-type/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How add-error-type Compares
| Feature / Agent | add-error-type | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Add a new custom error type for domain-specific errors. Use when creating errors for specific business rules or HTTP status codes. Triggers on "add error", "custom error", "error type".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Add Error Type
Adds a new domain error type that extends `BaseError`. All custom errors are defined in `src/errors.ts` and automatically handled by the global error handler.
## Quick Reference
**File**: `src/errors.ts`
**Base class**: `BaseError`
**Auto HTTP mapping**: `errorCode` number maps to HTTP status
## Existing Error Types
| Error Class | HTTP Status | Use Case |
| ------------------------- | ----------- | ------------------------------- |
| `BadRequestError` | 400 | Invalid input, validation fails |
| `UnauthenticatedError` | 401 | Missing or invalid credentials |
| `UnauthorizedError` | 403 | Lacks permission for action |
| `NotFoundError` | 404 | Resource doesn't exist |
| `InternalServerError` | 500 | Unexpected server errors |
| `ServiceUnavailableError` | 503 | External service down |
## Instructions
### Step 1: Add Error Class to `src/errors.ts`
```typescript
export class {ErrorName}Error extends BaseError {
constructor(
message: string = "Default error message",
options?: Omit<BaseErrorOptions, "errorCode">,
) {
super(message, { ...options, errorCode: {HTTP_STATUS_CODE} });
}
}
```
### Step 2: Use in Services/Controllers
```typescript
import { {ErrorName}Error } from "@/errors";
// Throw when condition is met
if (someCondition) {
throw new {ErrorName}Error("Specific error message");
}
// With cause for debugging
throw new {ErrorName}Error("Error message", { cause: originalError });
```
## Common HTTP Status Codes
| Code | Name | When to Use |
| ---- | --------------------- | ---------------------------------------- |
| 400 | Bad Request | Malformed request, validation failure |
| 401 | Unauthenticated | No credentials or invalid credentials |
| 403 | Forbidden | Valid credentials but lacks permission |
| 404 | Not Found | Resource doesn't exist |
| 409 | Conflict | Resource state conflict (duplicate, etc) |
| 422 | Unprocessable Entity | Semantic errors in valid syntax |
| 429 | Too Many Requests | Rate limiting |
| 500 | Internal Server Error | Unexpected server-side errors |
| 502 | Bad Gateway | Upstream service returned invalid |
| 503 | Service Unavailable | Server temporarily unavailable |
| 504 | Gateway Timeout | Upstream service timeout |
## Examples
### Conflict Error (409)
```typescript
export class ConflictError extends BaseError {
constructor(
message: string = "Resource conflict",
options?: Omit<BaseErrorOptions, "errorCode">,
) {
super(message, { ...options, errorCode: 409 });
}
}
// Usage
if (await repository.findByEmail(email)) {
throw new ConflictError("User with this email already exists");
}
```
### Rate Limit Error (429)
```typescript
export class RateLimitError extends BaseError {
constructor(
message: string = "Too many requests",
options?: Omit<BaseErrorOptions, "errorCode">,
) {
super(message, { ...options, errorCode: 429 });
}
}
// Usage
if (requestCount > limit) {
throw new RateLimitError("Rate limit exceeded. Try again later.");
}
```
### Validation Error (422)
```typescript
export class ValidationError extends BaseError {
constructor(
message: string = "Validation failed",
options?: Omit<BaseErrorOptions, "errorCode">,
) {
super(message, { ...options, errorCode: 422 });
}
}
// Usage with cause containing field errors
throw new ValidationError("Invalid input data", {
cause: { field: "email", message: "Invalid email format" },
});
```
### Gateway Error (502)
```typescript
export class BadGatewayError extends BaseError {
constructor(
message: string = "Bad Gateway",
options?: Omit<BaseErrorOptions, "errorCode">,
) {
super(message, { ...options, errorCode: 502 });
}
}
// Usage
if (!upstreamResponse.ok) {
throw new BadGatewayError("Upstream service returned invalid response");
}
```
### Using HttpError for One-off Status Codes
For status codes that don't need a dedicated class:
```typescript
import { HttpError } from "@/errors";
// One-off 451 (Unavailable For Legal Reasons)
throw new HttpError(451, "Content unavailable in your region");
// One-off 507 (Insufficient Storage)
throw new HttpError(507, "Storage quota exceeded");
```
## BaseError Structure
```typescript
export class BaseError extends Error {
public readonly cause?: unknown;
public readonly errorCode?: ErrorCode;
constructor(message: string, options?: BaseErrorOptions) {
super(message);
this.name = this.constructor.name;
this.cause = options?.cause;
this.errorCode = options?.errorCode;
Object.setPrototypeOf(this, new.target.prototype);
}
public toJSON(): { error: string; code?: ErrorCode; cause?: string } {
const json: { error: string; code?: ErrorCode; cause?: string } = {
error: this.message,
};
if (this.errorCode !== undefined) {
json.code = this.errorCode;
}
if (this.cause instanceof Error && this.cause.message) {
json.cause = this.cause.message;
}
return json;
}
}
```
## Global Error Handler
The `globalErrorHandler` in `src/errors.ts` automatically:
1. Logs the error
2. Converts `BaseError` instances to JSON responses
3. Maps `errorCode` to HTTP status
4. Wraps unknown errors in `InternalServerError`
```typescript
export const globalErrorHandler = (err: Error, c: Context<AppEnv>) => {
console.error(err);
if (err instanceof BaseError) {
return createErrorResponse(c, err); // Uses errorCode as HTTP status
} else if (err instanceof HTTPException) {
return c.json({ error: err.message }, err.status);
} else {
const internalError = new InternalServerError(
"An unexpected error occurred",
{ cause: err },
);
return createErrorResponse(c, internalError);
}
};
```
## What NOT to Do
- Do NOT catch and re-throw as generic Error (loses type info)
- Do NOT return error responses manually (use error classes)
- Do NOT use non-standard HTTP status codes without good reason
- Do NOT forget to set `errorCode` (defaults to 500)
- Do NOT put stack traces in error messages (use `cause` for debugging)
## See Also
- `create-middleware` - Global error handler setup
- `create-utility-service` - Error handling in services
- `create-controller` - Throwing errors from controllersRelated Skills
add_type
gwexpyに新しい配列型(Array/Series/Field)とコレクションを実装する
add-event-type
Add a new event type to the frontend feed system with corresponding React component. Use when user mentions "new event", "add event type", "event block", "new block type", or wants to display new agent output types.
21-build-error-reporting
Status: ACTIVE
1k-error-handling
Error handling patterns and best practices for OneKey. Use when implementing try/catch blocks, handling async errors, showing error messages, or managing error states in UI. Triggers on error, try, catch, exception, throw, fail, failure, error handling, error boundary, useAsyncCall, toast, fallback, error state.
modal-deployment
Run Python code in the cloud with serverless containers, GPUs, and autoscaling using Modal. This skill enables agents to generate code for deploying ML models, running batch jobs, serving APIs, and scaling compute-intensive workloads.
grail-miner
This skill assists in setting up, managing, and optimizing Grail miners on Bittensor Subnet 81, handling tasks like environment configuration, R2 storage, model checkpoint management, and performance tuning.
whisper-transcribe
Transcribes audio and video files to text using OpenAI's Whisper CLI, enhanced with contextual grounding from local markdown files for improved accuracy.
astro
This skill provides essential Astro framework patterns, focusing on server-side rendering (SSR), static site generation (SSG), middleware, and TypeScript best practices. It helps AI agents implement secure authentication, manage API routes, and debug rendering behaviors within Astro projects.
tech-blog
Generates comprehensive technical blog posts, offering detailed explanations of system internals, architecture, and implementation, either through source code analysis or document-driven research.
thor-skills
An entry point and router for AI agents to manage various THOR-related cybersecurity tasks, including running scans, analyzing logs, troubleshooting, and maintenance.
lets-go-rss
A lightweight, full-platform RSS subscription manager that aggregates content from YouTube, Vimeo, Behance, Twitter/X, and Chinese platforms like Bilibili, Weibo, and Douyin, featuring deduplication and AI smart classification.
ux
This AI agent skill provides comprehensive guidance for creating professional and insightful User Experience (UX) designs, covering user research, information architecture, interaction design, visual guidance, and usability evaluation. It aims to produce actionable, user-centered solutions that avoid generic AI aesthetics.