dood-stream-client
Version:
🚀 A feature-rich client for the DoodStream API with caching, logging, and error handling
42 lines (41 loc) • 1.21 kB
JavaScript
/**
* 🚨 Custom error class for DoodStream API errors
*/
export class DoodStreamApiError extends Error {
/**
* Create a new DoodStream API error
*
* @param message - Error message
* @param statusCode - HTTP status code
* @param response - Original response data
* @param context - Additional context information
*/
constructor(message, statusCode = 500, response, context) {
super(message);
this.name = "DoodStreamApiError";
this.statusCode = statusCode;
this.response = response;
this.context = context;
// Ensure proper prototype chain for instanceof checks
Object.setPrototypeOf(this, DoodStreamApiError.prototype);
}
/**
* 📝 Get a string representation of the error
*/
toString() {
return `${this.name} (${this.statusCode}): ${this.message}`;
}
/**
* 🧩 Convert the error to a plain object
*/
toJSON() {
return {
name: this.name,
message: this.message,
statusCode: this.statusCode,
response: this.response,
context: this.context,
stack: this.stack,
};
}
}