gristlabs_grist-core/app/common/ApiError.ts
Paul Fitzpatrick 6af811f7ab (core) give more detailed reasons for access denied when memos are present
Summary:
With this change, if a comment is added to an ACL formula, then that comment will be offered to the user if access is denied and that rule could potentially have granted access.

The code is factored so that when access is permitted, or when partially visible tables are being filtered, there is little overhead. Comments are gathered only when an explicit denial of access.

Test Plan: added tests, updated tests

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2730
2021-02-15 17:02:24 -05:00

43 lines
1.1 KiB
TypeScript

/**
* A tip for fixing an error.
*/
export interface ApiTip {
action: 'add-members' | 'upgrade' |'ask-for-help';
message: string;
}
/**
* Documentation of a limit relevant to an API error.
*/
export interface ApiLimit {
quantity: 'collaborators' | 'docs' | 'workspaces'; // what are we counting
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 {
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[];
memos?: string[];
}
/**
* An error with an http status code.
*/
export class ApiError extends Error {
constructor(message: string, public status: number, public details?: ApiErrorDetails) {
super(message);
}
}