-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: change error&error codes returned from /transaction/* related endpoints #1312
Conversation
cause, | ||
stack, | ||
}; | ||
throw new BadRequest('Failed to parse transaction.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a way we can continue including/returning the transaction/stack information as part of the error? This info can be useful when looking into specific issues/debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plus one to this, otherwise it looks really great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes exactly! 💯 Thank you both for pointing this out 🙏 I forgot to mention it in the PR description.
I tried to find a way to keep the stack and cause from extractCauseAndStack
for this exact reason that you mention but I was still getting a 500
error at the end. I will check some more to see how I can override the StatusCode
returned. Thank YOU both for your time on reviewing ! 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @TarikGul and @marshacb 🙏 to :
- point out the fact that we prefer keeping the debugging info and
- point in the direction of the
middleware
files for the error handling
Based on those sugegstions, I removed the BadRequest
solution (and also did not push the CustomBadRequest
solution which I was planning) and opted for the solution of passing the status code in the txErrorMiddleware
.
This implied the following changes :
- Reverted to the previous error handling with
extractCauseAndStack
- Added the
code
inerr
and passing it in thetxErrorMiddleware
- Reverted the changes to the test
.spec
files - Updated the mock files with the error code returned since now
err
also includes thecode
- Updated
ITxLegacyError
- Reverted changes in docs and rebuilt
Important Note
-
I am not setting a default value for
code
in thetxErrorMiddleware
so if it is not set in the service file or from wherever it is called then it will result in a500
status code and it will output a not so prettyerror: Invalid status code: undefined
. Maybe we would like to handle this more gracefully ? -
TODO from my side : Update the description of this PR to reflect the final implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this! Just a small question about the info returned in the error
…rrorMiddleware` - Reverted to the previous error handling with `extractCauseAndStack` - Added the `code` in error thrown and passed it in the `txErrorMiddleware` - Reverted the changes to the test `.spec` files - Updated the mock files with the error code returned since now `err` also includes the `code` - Updated `ITxLegacyError` - Reverted changes in docs and rebuilt
@@ -22,6 +22,7 @@ export function extractCauseAndStack(err: unknown): { | |||
cause: string | unknown; | |||
stack: string | undefined; | |||
} { | |||
// const code = err instanceof Error ? err : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just need to either remove or handle this commented out code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really amazing job! Lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Relates: #1311
Description
In the
transaction
related endpoints :/transaction
/transaction/dry-run
/transaction/fee-estimate
the errors are handled :
extractCauseAndStack
method (to extract thecause
andstack
of the error)txErrorMiddleware.ts
file and throws a hardcoded500
error here (also hardcoded in theinfo
here)With the changes in the current PR, we are now handling the errors in the following way :
extractCauseAndStack
methodtxErrorMiddleware.ts
file400
instead of500
txErrorMiddleware.ts
file again but now with the error code set already.This change was mentioned in the #1311 issue and it was concerning only the
/transaction
endpoint. However, I think it also fits in the rest of thetransaction
related endpoints since the logic is the same, meaning If we decide to throw a400
error if a tx fails to be submitted then we should throw the same error if a tx fails to be dry-run. And also if we fail to retrieve the fee info.Return Errors & Error Codes
Example Returned Error before the change
Example Returned Error after the change
Returned Errors Comparison
So with this change :
400
instead of500
) andcode
error
transaction
cause
stack
Example Request that will/should trigger a 400 error
while ofc a sidecar instance (checked out in the current branch) is running locally.
Credits to @TarikGul and @marshacb for the very insightful observations/reviews on this PR so we can choose the best solution/implementation.