misplaced-axios-check
isAxiosError(x) (or axios.isAxiosError(x)) where x can't be an HTTP library's error: the error of a Result that a project function returns with its own error type, or the error of a catch whose try holds only calls that return a Result. An idiomatic rule: reported only with "safe-ts": { "idiomatic": true } in package.json.
Why: a dialog that showed a server's refusal (isAxiosError(error) && error.response?.status === 422) stops showing it when the request function starts returning its own error type, and nothing says so: the test is simply never true, and the generic message takes over. Read the error the function returns.
✕ Rejectedmisplaced-axios-check
ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
declare function isAxiosError(error: unknown): boolean;
export type DeployError = Enum<{ NoProject: {}; Refused: { reason: string } }>;
export const DeployError = constructors<DeployError>();
export async function deploy(id: string): Promise<Result<string, DeployError>> {
return id === "" ? err(DeployError.NoProject()) : `deployed ${id}`;
}
export async function onDeploy(id: string, show: (text: string) => void): Promise<void> {
const done = await deploy(id);
if (isErr(done) && isAxiosError(done.error)) show("refused");
}ts
import { constructors, type Enum } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
declare function isAxiosError(error: unknown): boolean;
export type DeployError = Enum<{ NoProject: {}; Refused: { reason: string } }>;
export const DeployError = constructors<DeployError>();
export async function deploy(id: string): Promise<Result<string, DeployError>> {
return id === "" ? err(({ tag: "NoProject" } satisfies DeployError as DeployError)) : `deployed ${id}`;
}
export async function onDeploy(id: string, show: (text: string) => void): Promise<void> {
const done = await deploy(id);
if (isErr(done) && isAxiosError(done.error)) show("refused");
}✓ Accepted0 diagnostics
ts
import { constructors, type Enum, match } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
export type DeployError = Enum<{ NoProject: {}; Refused: { reason: string } }>;
export const DeployError = constructors<DeployError>();
export async function deploy(id: string): Promise<Result<string, DeployError>> {
return id === "" ? err(DeployError.NoProject()) : `deployed ${id}`;
}
export async function onDeploy(id: string, show: (text: string) => void): Promise<void> {
const done = await deploy(id);
if (!isErr(done)) return;
show(
match(done.error, {
NoProject: () => "Pick a project first",
Refused: ({ reason }) => `Refused: ${reason}`,
}),
);
}ts
import { constructors, type Enum, match } from "@evobug_com/safe-ts-std/enum";
import { err, isErr, type Result } from "@evobug_com/safe-ts-std/result";
export type DeployError = Enum<{ NoProject: {}; Refused: { reason: string } }>;
export const DeployError = constructors<DeployError>();
export async function deploy(id: string): Promise<Result<string, DeployError>> {
return id === "" ? err(({ tag: "NoProject" } satisfies DeployError as DeployError)) : `deployed ${id}`;
}
export async function onDeploy(id: string, show: (text: string) => void): Promise<void> {
const done = await deploy(id);
if (!isErr(done)) return;
show(
match(done.error, {
NoProject: () => "Pick a project first",
Refused: ({ reason }) => `Refused: ${reason}`,
}),
);
}What it can see. The value must come from a call the checker follows to a checked function: const r = await f(); ... isAxiosError(r.error), with f declared Promise<Result<T, E>> and E not unknown and not an axios type. A function that rejects with an error class of its own (rather than returning a Result) can't be told apart from one that lets the axios error through, so that case, where the report that led to this rule started, is found only once the function returns a Result.