Skip to content

Commit

Permalink
Error reporting improvments
Browse files Browse the repository at this point in the history
The goal is to provide a platformized way to distinguish between errors at the Fusion layer.

Today, errors are handled in one generic manner. Whether they are client type errors (ie validation, not found) or server type errors (ie authorization, server failures), these errors are logged the same and frontend applications classify them all the same without custom handling.

Having these errors undistinguished creates a difficulty in filtering out specific error types that require different handling. This handling includes alerting on some error types but not others. For example:

Co-authored-by: shYkiSto <siarhei@uber.com>
  • Loading branch information
2 people authored and fusionjs-sync-bot[bot] committed Sep 6, 2022
1 parent f9bb3e1 commit 11f844f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
24 changes: 21 additions & 3 deletions fusion-plugin-rpc/src/response-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,29 @@
export default class ResponseError extends Error {
code: ?string;
meta: ?Object;
cause: ?mixed;
severity: ?$Values<typeof ResponseError.Severity>;

constructor(message: string) {
static Severity = Object.freeze({
HIGH: 'HIGH',
MEDIUM: 'MEDIUM',
});

constructor(
message: string,
options?: ?{
code?: string,
meta?: Object,
cause?: mixed,
severity?: $Values<typeof ResponseError.Severity>,
}
) {
super(message);
this.code = null;
this.meta = null;
const {code, meta, cause, severity} = options ?? {};
this.code = code;
this.meta = meta;
this.cause = cause;
this.severity = severity;
Error.captureStackTrace(this, ResponseError);
}
}
4 changes: 3 additions & 1 deletion fusion-plugin-rpc/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ const pluginFactory: () => RPCPluginType = () =>
e instanceof ResponseError
? e
: new Error(
'UnknownError - Use ResponseError from fusion-plugin-rpc (or fusion-plugin-rpc-redux-react if you are using React) package for more detailed error messages'
__DEV__
? 'UnknownError - Use ResponseError from fusion-plugin-rpc (or fusion-plugin-rpc-redux-react if you are using React) package for more detailed error messages'
: 'Internal Server Error'
);
ctx.body = {
status: 'failure',
Expand Down

0 comments on commit 11f844f

Please sign in to comment.