2023-03-28 21:32:54 +08:00
|
|
|
export function assert(condition: boolean, msg: string) {
|
|
|
|
if (!condition) {
|
|
|
|
throwError(msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function throwError(msg: string): void {
|
2023-04-02 18:26:24 +08:00
|
|
|
const error = new Error(`[axios-miniprogram]: ${msg}`);
|
|
|
|
cleanStack(error);
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function cleanStack(error: Error) {
|
2023-04-03 21:03:33 +08:00
|
|
|
const { stack } = error;
|
|
|
|
if (stack) {
|
|
|
|
const start = stack.indexOf('at');
|
|
|
|
const end = stack.search(/at ([\w-_.]+:)?\//i);
|
2023-04-02 23:27:45 +08:00
|
|
|
if (start < end) {
|
2023-04-03 21:03:33 +08:00
|
|
|
const removed = stack.slice(start, end);
|
|
|
|
error.stack = stack.replace(removed, '');
|
2023-04-02 18:26:24 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-28 21:32:54 +08:00
|
|
|
}
|