phonic
Version:
[](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FPhonic-Co%2Fphonic-node) [ • 953 B
JavaScript
// This file was auto-generated by Fern from our API Definition.
import { toJson } from "../core/json.mjs";
export class PhonicError extends Error {
constructor({ message, statusCode, body, rawResponse, }) {
super(buildMessage({ message, statusCode, body }));
Object.setPrototypeOf(this, new.target.prototype);
if (Error.captureStackTrace) {
Error.captureStackTrace(this, this.constructor);
}
this.name = this.constructor.name;
this.statusCode = statusCode;
this.body = body;
this.rawResponse = rawResponse;
}
}
function buildMessage({ message, statusCode, body, }) {
const lines = [];
if (message != null) {
lines.push(message);
}
if (statusCode != null) {
lines.push(`Status code: ${statusCode.toString()}`);
}
if (body != null) {
lines.push(`Body: ${toJson(body, undefined, 2)}`);
}
return lines.join("\n");
}