fix(chat): lower unavailable media logs
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { AppException, ExceptionCode } from "@/core/errors";
|
||||
|
||||
import { Result, toError } from "../result";
|
||||
|
||||
afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe("Result error normalization", () => {
|
||||
it("normalizes unknown thrown values to AppException", async () => {
|
||||
const result = await Result.wrap(async () => {
|
||||
@@ -25,4 +29,25 @@ describe("Result error normalization", () => {
|
||||
expect(error.message).toBe("Network connection failed.");
|
||||
expect((error as AppException).code).toBe(ExceptionCode.network);
|
||||
});
|
||||
|
||||
it("allows expected failures to be logged at info level", async () => {
|
||||
const info = vi.spyOn(console, "info").mockImplementation(() => undefined);
|
||||
const error = vi
|
||||
.spyOn(console, "error")
|
||||
.mockImplementation(() => undefined);
|
||||
|
||||
const result = await Result.wrap(
|
||||
async () => {
|
||||
throw new Error("expected failure");
|
||||
},
|
||||
{ errorLogLevel: "info" },
|
||||
);
|
||||
|
||||
expect(Result.isErr(result)).toBe(true);
|
||||
expect(info).toHaveBeenCalledWith(
|
||||
expect.stringContaining("INFO [Result] Result.wrap caught exception"),
|
||||
expect.any(Object),
|
||||
);
|
||||
expect(error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user