@formbricks/errors
Error handling for @formbricks packages
Installation
npm install @formbricks/errors
Usage
import { Result, ok, err, okVoid } from "@formbricks/errors";
type CustomError = {
code: "custom_error";
message: string;
};
type AnotherCustomError = {
code: "another_custom_error";
message: string;
anotherField: number;
};
type SuccessType = {
id: string;
};
const test = (): Result<SuccessType, CustomError | AnotherCustomError> => {
};
const result = test();
if (result.ok === true) {
console.log(result.value.id);
} else if (result.error.code === "custom_error") {
console.log(result.error.message);
} else if (result.error.code === "another_custom_error") {
console.log(result.error.anotherField);
console.log(result.error.message);
}
Inspiration