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
4 changes: 2 additions & 2 deletions core/src/exchanges/baozi/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ export class BaoziErrorMapper extends ErrorMapper {
super('Baozi');
}

mapError(error: any): BaseError {
mapError(error: unknown): BaseError {
// Handle Solana transaction errors
if (error?.message) {
if (error instanceof Error) {
const msg = error.message;

// Solana insufficient funds
Expand Down
10 changes: 5 additions & 5 deletions core/src/exchanges/gemini-titan/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class GeminiErrorMapper extends ErrorMapper {
super('GeminiTitan');
}

protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
if (axios.isAxiosError(error) && error.response?.data) {
const data = error.response.data;
if (typeof data === 'string') {
Expand All @@ -40,9 +40,9 @@ export class GeminiErrorMapper extends ErrorMapper {
return super.extractErrorMessage(error);
}

protected mapBadRequestError(message: string, data: any): BadRequest {
const reason = typeof data === 'object' && data?.reason
? String(data.reason)
protected mapBadRequestError(message: string, data: unknown): BadRequest {
const reason = typeof data === 'object' && data !== null && 'reason' in data
? String((data as Record<string, unknown>).reason)
: '';
const lowerReason = reason.toLowerCase();
const lowerMessage = message.toLowerCase();
Expand Down Expand Up @@ -74,7 +74,7 @@ export class GeminiErrorMapper extends ErrorMapper {
return super.mapBadRequestError(message, data);
}

mapError(error: any): ReturnType<ErrorMapper['mapError']> {
mapError(error: unknown): ReturnType<ErrorMapper['mapError']> {
if (axios.isAxiosError(error) && error.response?.status === 429) {
const retryAfter = error.response.headers?.['retry-after'];
const retryAfterSeconds = retryAfter ? parseInt(retryAfter, 10) : undefined;
Expand Down
10 changes: 5 additions & 5 deletions core/src/exchanges/hyperliquid/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class HyperliquidErrorMapper extends ErrorMapper {
super('Hyperliquid');
}

protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
if (axios.isAxiosError(error) && error.response?.data) {
const data = error.response.data;
if (typeof data === 'string') {
Expand All @@ -35,10 +35,10 @@ export class HyperliquidErrorMapper extends ErrorMapper {
return super.extractErrorMessage(error);
}

protected mapBadRequestError(message: string, data: any): BadRequest {
protected mapBadRequestError(message: string, data: unknown): BadRequest {
const lowerMessage = message.toLowerCase();
const responseStr = typeof data === 'object' && data?.response
? String(data.response).toLowerCase()
const responseStr = typeof data === 'object' && data !== null && 'response' in data
? String((data as Record<string, unknown>).response).toLowerCase()
: lowerMessage;

if (responseStr.includes('insufficient margin') || responseStr.includes('not enough')) {
Expand All @@ -56,7 +56,7 @@ export class HyperliquidErrorMapper extends ErrorMapper {
return super.mapBadRequestError(message, data);
}

mapError(error: any): ReturnType<ErrorMapper['mapError']> {
mapError(error: unknown): ReturnType<ErrorMapper['mapError']> {
if (axios.isAxiosError(error) && error.response?.status === 429) {
const retryAfter = error.response.headers?.['retry-after'];
const retryAfterSeconds = retryAfter ? parseInt(retryAfter, 10) : undefined;
Expand Down
4 changes: 2 additions & 2 deletions core/src/exchanges/kalshi/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class KalshiErrorMapper extends ErrorMapper {
/**
* Override to handle Kalshi-specific error patterns
*/
protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
// Handle Kalshi API errors
if (axios.isAxiosError(error) && error.response?.data) {
const data = error.response.data;
Expand All @@ -44,7 +44,7 @@ export class KalshiErrorMapper extends ErrorMapper {
/**
* Override to detect Kalshi-specific error patterns
*/
protected mapBadRequestError(message: string, data: any): BadRequest {
protected mapBadRequestError(message: string, data: unknown): BadRequest {
const lowerMessage = message.toLowerCase();

// Kalshi-specific insufficient funds detection
Expand Down
4 changes: 2 additions & 2 deletions core/src/exchanges/limitless/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class LimitlessErrorMapper extends ErrorMapper {
/**
* Override to handle Limitless-specific error patterns
*/
protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
// Handle Limitless CLOB errors (similar to Polymarket)
if (axios.isAxiosError(error) && error.response?.data) {
const data = error.response.data;
Expand All @@ -45,7 +45,7 @@ export class LimitlessErrorMapper extends ErrorMapper {
/**
* Override to detect Limitless-specific error patterns
*/
protected mapBadRequestError(message: string, data: any): BadRequest {
protected mapBadRequestError(message: string, data: unknown): BadRequest {
const lowerMessage = (message || '').toString().toLowerCase();

// Limitless-specific authentication errors (400 status)
Expand Down
8 changes: 4 additions & 4 deletions core/src/exchanges/metaculus/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class MetaculusErrorMapper extends ErrorMapper {
super('Metaculus');
}

protected override mapNotFoundError(message: string, _data: any): NotFound {
protected override mapNotFoundError(message: string, _data: unknown): NotFound {
const lower = message.toLowerCase();
if (lower.includes('question') || lower.includes('market')) {
const match = message.match(/[\d]+/);
Expand All @@ -33,7 +33,7 @@ export class MetaculusErrorMapper extends ErrorMapper {
return new NotFound(message, this.exchangeName);
}

protected override mapBadRequestError(message: string, data: any): BadRequest {
protected override mapBadRequestError(message: string, data: unknown): BadRequest {
const lower = message.toLowerCase();

// Probability validation errors from the forecast API
Expand All @@ -57,8 +57,8 @@ export class MetaculusErrorMapper extends ErrorMapper {
protected override mapByStatusCode(
status: number,
message: string,
data: any,
response?: any,
data: unknown,
response?: unknown,
): BaseError {
if (status === 401) {
return new AuthenticationError(
Expand Down
4 changes: 2 additions & 2 deletions core/src/exchanges/myriad/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class MyriadErrorMapper extends ErrorMapper {
super('Myriad');
}

protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
if (axios.isAxiosError(error) && error.response?.data) {
const data = error.response.data;
if (data.message) return data.message;
Expand All @@ -16,7 +16,7 @@ export class MyriadErrorMapper extends ErrorMapper {
return super.extractErrorMessage(error);
}

protected mapBadRequestError(message: string, data: any): BadRequest {
protected mapBadRequestError(message: string, data: unknown): BadRequest {
const lowerMessage = message.toLowerCase();
if (lowerMessage.includes('insufficient') || lowerMessage.includes('liquidity')) {
return new BadRequest(message, this.exchangeName);
Expand Down
11 changes: 6 additions & 5 deletions core/src/exchanges/opinion/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class OpinionErrorMapper extends ErrorMapper {
super('Opinion');
}

protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
if (axios.isAxiosError(error) && error.response?.data) {
const data = error.response.data;
// OpenAPI format uses "msg", SDK format uses "errmsg"
Expand All @@ -19,12 +19,13 @@ export class OpinionErrorMapper extends ErrorMapper {
return super.extractErrorMessage(error);
}

protected mapBadRequestError(message: string, data: any): BadRequest {
if (data && typeof data === 'object') {
protected mapBadRequestError(message: string, data: unknown): BadRequest {
if (typeof data === 'object' && data !== null) {
const obj = data as Record<string, unknown>;
// OpenAPI format: { code: number, msg: string }
// SDK format: { errno: number, errmsg: string }
const errorCode = data.code ?? data.errno;
const errorMsg = data.msg || data.errmsg || message;
const errorCode = obj.code ?? obj.errno;
const errorMsg = obj.msg || obj.errmsg || message;
if (errorCode !== undefined && errorCode !== 0) {
return new BadRequest(
`Opinion API error (code ${errorCode}): ${errorMsg}`,
Expand Down
6 changes: 3 additions & 3 deletions core/src/exchanges/polymarket/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class PolymarketErrorMapper extends ErrorMapper {
* `errorMsg` path for any residual V1 responses (order submission still
* returns `errorMsg` in some batch flows).
*/
protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
if (axios.isAxiosError(error) && error.response?.data) {
const data = error.response.data;

Expand All @@ -54,7 +54,7 @@ export class PolymarketErrorMapper extends ErrorMapper {
/**
* Override to handle V2 status code 425 (Too Early -- matching engine restarting)
*/
protected mapByStatusCode(status: number, message: string, data: any, response?: any): BaseError {
protected mapByStatusCode(status: number, message: string, data: unknown, response?: unknown): BaseError {
if (status === 425) {
return new ExchangeNotAvailable(
`Matching engine restarting: ${message}`,
Expand All @@ -68,7 +68,7 @@ export class PolymarketErrorMapper extends ErrorMapper {
/**
* Override to detect Polymarket-specific error patterns in 400 responses
*/
protected mapBadRequestError(message: string, data: any): BadRequest {
protected mapBadRequestError(message: string, data: unknown): BadRequest {
const lowerMessage = message.toLowerCase();

// Signature type / maker address mismatch — the most common auth
Expand Down
8 changes: 4 additions & 4 deletions core/src/exchanges/probable/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class ProbableErrorMapper extends ErrorMapper {
super('Probable');
}

protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
if (axios.isAxiosError(error) && error.response?.data) {
const data = error.response.data;

Expand All @@ -25,14 +25,14 @@ export class ProbableErrorMapper extends ErrorMapper {
}

// Handle @prob/clob SDK error objects
if (error && typeof error === 'object' && error.msg) {
return String(error.msg);
if (typeof error === 'object' && error !== null && 'msg' in error) {
return String((error as Record<string, unknown>).msg);
}

return super.extractErrorMessage(error);
}

protected mapBadRequestError(message: string, data: any): BadRequest {
protected mapBadRequestError(message: string, data: unknown): BadRequest {
const lowerMessage = message.toLowerCase();

// SDK auth failures
Expand Down
20 changes: 14 additions & 6 deletions core/src/exchanges/smarkets/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class SmarketsErrorMapper extends ErrorMapper {
/**
* Override to handle the Smarkets { error_type, data } format
*/
protected extractErrorMessage(error: any): string {
protected extractErrorMessage(error: unknown): string {
if (axios.isAxiosError(error) && error.response?.data) {
const body = error.response.data;
const errorType = body.error_type;
Expand All @@ -124,7 +124,7 @@ export class SmarketsErrorMapper extends ErrorMapper {
* Override to map Smarkets error_type values before falling back
* to the default status-code-based mapping
*/
mapError(error: any): ReturnType<ErrorMapper['mapError']> {
mapError(error: unknown): ReturnType<ErrorMapper['mapError']> {
if (axios.isAxiosError(error) && error.response?.data) {
const errorType: string | undefined = error.response.data.error_type;

Expand All @@ -143,8 +143,11 @@ export class SmarketsErrorMapper extends ErrorMapper {
/**
* Override to detect order-specific errors within 400 responses
*/
protected mapBadRequestError(message: string, data: any): BadRequest {
const errorType: string | undefined = data?.error_type;
protected mapBadRequestError(message: string, data: unknown): BadRequest {
const errorType: string | undefined =
typeof data === 'object' && data !== null && 'error_type' in data
? String((data as Record<string, unknown>).error_type)
: undefined;

if (errorType) {
if (INSUFFICIENT_FUNDS_ERRORS.has(errorType)) {
Expand Down Expand Up @@ -172,14 +175,19 @@ export class SmarketsErrorMapper extends ErrorMapper {
private mapByErrorType(
errorType: string,
message: string,
response: any
response: unknown
): ReturnType<ErrorMapper['mapError']> | undefined {
if (AUTHENTICATION_ERRORS.has(errorType)) {
return new AuthenticationError(message, this.exchangeName);
}

if (RATE_LIMIT_ERRORS.has(errorType)) {
const retryAfter = response?.headers?.['retry-after'];
const headers = (
typeof response === 'object' && response !== null && 'headers' in response
? (response as { headers?: Record<string, string> }).headers
: undefined
);
const retryAfter = headers?.['retry-after'];
const retryAfterSeconds = retryAfter
? parseInt(retryAfter, 10)
: undefined;
Expand Down
Loading
Loading