2020-07-21 13:20:51 +00:00
|
|
|
/**
|
|
|
|
* A tip for fixing an error.
|
|
|
|
*/
|
|
|
|
export interface ApiTip {
|
2023-07-05 15:36:45 +00:00
|
|
|
action: 'add-members' | 'upgrade' | 'ask-for-help' | 'manage';
|
2020-07-21 13:20:51 +00:00
|
|
|
message: string;
|
|
|
|
}
|
|
|
|
|
2023-07-05 15:36:45 +00:00
|
|
|
export type LimitType = 'collaborators' | 'docs' | 'workspaces' | 'assistant';
|
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
/**
|
|
|
|
* Documentation of a limit relevant to an API error.
|
|
|
|
*/
|
|
|
|
export interface ApiLimit {
|
2023-07-05 15:36:45 +00:00
|
|
|
quantity: LimitType; // what are we counting
|
2020-07-21 13:20:51 +00:00
|
|
|
subquantity?: string; // a nuance to what we are counting
|
|
|
|
maximum: number; // maximum allowed
|
|
|
|
value: number; // current value of quantity for user
|
|
|
|
projectedValue: number; // value of quantity expected if request had been allowed
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Structured details about an API error.
|
|
|
|
*/
|
|
|
|
export interface ApiErrorDetails {
|
2023-12-05 08:15:09 +00:00
|
|
|
code?: ApiErrorCode;
|
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
limit?: ApiLimit;
|
|
|
|
|
|
|
|
// If set, this is the more user-friendly message to show to the user than error.message.
|
|
|
|
userError?: string;
|
|
|
|
|
|
|
|
// If set, contains suggestions for fixing a problem.
|
|
|
|
tips?: ApiTip[];
|
2021-02-15 21:36:33 +00:00
|
|
|
|
|
|
|
memos?: string[];
|
2020-07-21 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
2023-12-05 08:15:09 +00:00
|
|
|
export type ApiErrorCode =
|
2024-01-24 09:58:19 +00:00
|
|
|
| 'UserNotConfirmed'
|
2024-02-21 19:22:01 +00:00
|
|
|
| 'FormNotFound'
|
|
|
|
| 'FormNotPublished';
|
2023-12-05 08:15:09 +00:00
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
/**
|
|
|
|
* An error with an http status code.
|
|
|
|
*/
|
|
|
|
export class ApiError extends Error {
|
|
|
|
constructor(message: string, public status: number, public details?: ApiErrorDetails) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
}
|