Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/schema/GetSchemaTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { CfnService } from '../services/CfnService';
import { LoggerFactory } from '../telemetry/LoggerFactory';
import { ScopedTelemetry } from '../telemetry/ScopedTelemetry';
import { Measure, Telemetry } from '../telemetry/TelemetryDecorator';
import { classifyAwsError } from '../utils/AwsErrorMapper';
import { AwsRegion } from '../utils/Region';
import { downloadFile } from '../utils/RemoteDownload';
import { PrivateSchemas, PrivateSchemasType, PrivateStoreKey } from './PrivateSchemas';
Expand Down Expand Up @@ -73,6 +74,9 @@ export class GetPublicSchemaTask extends GetSchemaTask {
export class GetPrivateSchemasTask extends GetSchemaTask {
private readonly logger = LoggerFactory.getLogger(GetPrivateSchemasTask);

@Telemetry()
private readonly telemetry!: ScopedTelemetry;

constructor(private readonly getSchemas: () => Promise<DescribeTypeOutput[]>) {
super();
}
Expand All @@ -94,6 +98,10 @@ export class GetPrivateSchemasTask extends GetSchemaTask {

this.logger.info(`${schemas.length} private schemas retrieved`);
} catch (error) {
const { category, httpStatus } = classifyAwsError(error);
this.telemetry.count('getSchemas.error', 1, {
attributes: { category, httpStatus },
});
this.logger.error(error, 'Failed to get private schemas');
throw error;
}
Expand Down
28 changes: 28 additions & 0 deletions src/utils/AwsErrorMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,34 @@ function isRetryableAwsError(error: AwsError): boolean {
return statusCode !== undefined && RETRYABLE_STATUS_CODES.has(statusCode);
}

export type AwsErrorCategory = 'credentials' | 'network' | 'permissions' | 'throttling' | 'service' | 'unknown';

export function classifyAwsError(error: unknown): { category: AwsErrorCategory; httpStatus?: number } {
if (!isAwsError(error)) {
return { category: 'unknown' };
}

const httpStatus = error.$metadata?.httpStatusCode;

if (isCredentialError(error)) {
return { category: 'credentials', httpStatus };
}
if (isNetworkError(error)) {
return { category: 'network', httpStatus };
}
if (error.name === 'AccessDeniedException' || httpStatus === 403) {
return { category: 'permissions', httpStatus };
}
if (error.name === 'ThrottlingException' || httpStatus === 429) {
return { category: 'throttling', httpStatus };
}
if (httpStatus !== undefined) {
return { category: 'service', httpStatus };
}

return { category: 'unknown' };
}

export function mapAwsErrorToLspError(error: unknown): ResponseError<unknown> {
if (error instanceof ResponseError) {
return error;
Expand Down
Loading