import { ConfigurationError, UserInputError } from "./errors-D_R568zP.js";
import { logIssue } from "./logging-DqqDTe02.js";
import { ApiClientError, ApiError, ApiServerError } from "./errors-CQZ-QlOB.js";

//#region src/internal/error-handling.ts
/**
* Type guard to identify user input validation errors.
*/
function isUserInputError(error) {
	return error instanceof UserInputError;
}
/**
* Type guard to identify configuration errors.
*/
function isConfigurationError(error) {
	return error instanceof ConfigurationError;
}
/**
* Type guard to identify API errors.
*/
function isApiError(error) {
	return error instanceof ApiError;
}
/**
* Type guard to identify API client errors (4xx).
*/
function isApiClientError(error) {
	return error instanceof ApiClientError;
}
/**
* Type guard to identify API server errors (5xx).
*/
function isApiServerError(error) {
	return error instanceof ApiServerError;
}
/**
* Format an error for user display with markdown formatting.
* This is used by tool handlers to format errors for MCP responses.
*
* SECURITY: Only return trusted error messages to prevent prompt injection vulnerabilities.
* We trust: Sentry API errors, our own UserInputError/ConfigurationError messages, and system templates.
*/
async function formatErrorForUser(error) {
	if (isUserInputError(error)) return [
		"**Input Error**",
		"It looks like there was a problem with the input you provided.",
		error.message,
		`You may be able to resolve the issue by addressing the concern and trying again.`
	].join("\n\n");
	if (isConfigurationError(error)) return [
		"**Configuration Error**",
		"There appears to be a configuration issue with your setup.",
		error.message,
		`Please check your environment configuration and try again.`
	].join("\n\n");
	if (isApiClientError(error)) {
		const statusText = error.status ? `There was an HTTP ${error.status} error with your request to the Sentry API.` : "There was an error with your request.";
		return [
			"**Input Error**",
			statusText,
			error.toUserMessage(),
			`You may be able to resolve the issue by addressing the concern and trying again.`
		].join("\n\n");
	}
	if (isApiServerError(error)) {
		const eventId$1 = logIssue(error);
		const statusText = error.status ? `There was an HTTP ${error.status} server error with the Sentry API.` : "There was a server error.";
		return [
			"**Error**",
			statusText,
			`${error.message}`,
			`**Event ID**: ${eventId$1}`,
			`Please contact support with this Event ID if the problem persists.`
		].join("\n\n");
	}
	if (isApiError(error)) {
		const statusText = error.status ? `There was an HTTP ${error.status} error with your request to the Sentry API.` : "There was an error with your request.";
		return [
			"**Error**",
			statusText,
			`${error.message}`,
			`You may be able to resolve the issue by addressing the concern and trying again.`
		].join("\n\n");
	}
	const eventId = logIssue(error);
	return [
		"**Error**",
		"It looks like there was a problem communicating with the Sentry API.",
		"Please report the following to the user for the Sentry team:",
		`**Event ID**: ${eventId}`,
		process.env.NODE_ENV !== "production" ? error instanceof Error ? error.message : String(error) : ""
	].filter(Boolean).join("\n\n");
}

//#endregion
export { formatErrorForUser, isApiClientError, isApiError, isApiServerError, isConfigurationError, isUserInputError };
//# sourceMappingURL=error-handling-D_4c-JgK.js.map