UNPKG

@ritas-inc/sapb1commandapi-client

Version:

A stateless TypeScript client for SAP B1 Service Layer Command API with comprehensive error handling, type safety, and batch operations

62 lines (61 loc) 1.61 kB
export class SAPB1APIError extends Error { status; type; title; detail; instance; context; issues; constructor(errorResponse) { super(errorResponse.detail); this.name = 'SAPB1APIError'; this.status = errorResponse.status; this.type = errorResponse.type; this.title = errorResponse.title; this.detail = errorResponse.detail; this.instance = errorResponse.instance; this.context = errorResponse.context; this.issues = errorResponse.issues; } toJSON() { return { name: this.name, status: this.status, type: this.type, title: this.title, detail: this.detail, instance: this.instance, context: this.context, issues: this.issues }; } } export class AuthError extends SAPB1APIError { constructor(errorResponse) { super(errorResponse); this.name = 'AuthError'; } } export class NetworkError extends Error { code; request; response; constructor(message, code, request, response) { super(message); this.name = 'NetworkError'; this.code = code; this.request = request; this.response = response; } } export class ValidationError extends Error { issues; constructor(message, issues) { super(message); this.name = 'ValidationError'; this.issues = issues; } } export function isErrorResponse(response) { return response?.success === false && response?.problem !== undefined; }