-
Notifications
You must be signed in to change notification settings - Fork 71
Node api finality #1897
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
Node api finality #1897
Changes from all commits
d5bcb7d
4be1b1e
52af168
d033dc9
402ef6f
1caf2a1
82a7a2e
aac66f8
350e93d
9b96f0f
20bf1d8
282bf9f
cd82ba3
51f714d
44ad778
40c3d02
5dce8da
b77abc1
6e83e89
2bfd983
d17d321
a504094
1258e13
8b80e20
57f2cf6
475f2cd
a8b563f
9bbf167
1a9ba80
3ff25c5
5b92751
458f4b3
6a3355f
3c38c2a
eec3dca
ef98afe
80c59d1
9302d0d
8b84ccc
2426b31
e4ce47b
cd3b937
3df7ae6
270f398
ae48b55
bfb4ac9
f815e96
c7f964d
67f82e3
0057141
0f7a7b1
e057365
34bdf95
426e67a
3134453
37b3522
bb0c09e
57ad53a
d513e1a
743846e
8c4cb9b
022ac5f
160416f
7b1e186
46cabb3
a2ac998
ac0eab9
32413f5
bff2a60
e227184
c623adc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,20 +18,6 @@ var ( | |
| notFound = errors.New("not found") | ||
| ) | ||
|
|
||
| // BadRequestError represents a bad request error. | ||
| // Deprecated: don't use this error type in new code. Create a new error type or value in 'pkg/api/errors' package. | ||
| type BadRequestError struct { | ||
| inner error | ||
| } | ||
|
|
||
| func wrapToBadRequestError(err error) *BadRequestError { | ||
| return &BadRequestError{inner: err} | ||
| } | ||
|
|
||
| func (e *BadRequestError) Error() string { | ||
| return e.inner.Error() | ||
| } | ||
|
|
||
| // AuthError represents an authentication error or problem. | ||
| // Deprecated: don't use this error type in new code. Create a new error type or value in 'pkg/api/errors' package. | ||
| type AuthError struct { | ||
|
|
@@ -62,17 +48,18 @@ func (eh *ErrorHandler) Handle(w http.ResponseWriter, r *http.Request, err error | |
| } | ||
| // target errors | ||
| var ( | ||
| badRequestError *BadRequestError | ||
| authError *AuthError | ||
| unknownError *apiErrs.UnknownError | ||
| apiError apiErrs.ApiError | ||
| badRequestError *apiErrs.BadRequestError | ||
| authError *AuthError | ||
| unknownError *apiErrs.UnknownError | ||
| apiError apiErrs.ApiError | ||
| unavailableError *apiErrs.UnavailableError | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New error should implement
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They already do
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then you can remove specific cases. One |
||
| // check that all targets implement the error interface | ||
| _, _, _, _ = error(badRequestError), error(authError), error(unknownError), error(apiError) | ||
| _, _, _, _, _ = error(badRequestError), error(authError), error(unknownError), | ||
| error(apiError), error(unavailableError) | ||
| ) | ||
| switch { | ||
| case errors.As(err, &badRequestError): | ||
| // nickeskov: this error type will be removed in future | ||
| http.Error(w, fmt.Sprintf("Failed to complete request: %s", badRequestError.Error()), http.StatusBadRequest) | ||
| eh.sendApiErrJSON(w, r, badRequestError) | ||
| case errors.As(err, &authError): | ||
| // nickeskov: this error type will be removed in future | ||
| http.Error(w, fmt.Sprintf("Failed to complete request: %s", authError.Error()), http.StatusForbidden) | ||
|
|
@@ -86,6 +73,8 @@ func (eh *ErrorHandler) Handle(w http.ResponseWriter, r *http.Request, err error | |
| eh.sendApiErrJSON(w, r, unknownError) | ||
| case errors.As(err, &apiError): | ||
| eh.sendApiErrJSON(w, r, apiError) | ||
| case errors.As(err, &unavailableError): | ||
| eh.sendApiErrJSON(w, r, unavailableError) | ||
|
Comment on lines
+76
to
+77
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| default: | ||
| eh.logger.Error("InternalServerError", | ||
| slog.String("proto", r.Proto), | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -114,11 +114,119 @@ type WrongJsonError struct { | |||||
| func NewWrongJsonError(cause string, validationErrors []error) *WrongJsonError { | ||||||
| return &WrongJsonError{ | ||||||
| genericError: genericError{ | ||||||
| ID: WrongJsonErrorID, | ||||||
| ID: WrongJSONErrorID, | ||||||
| HttpCode: http.StatusBadRequest, | ||||||
| Message: "failed to parse json message", | ||||||
| }, | ||||||
| Cause: cause, | ||||||
| ValidationErrors: validationErrors, | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // UnavailableError UnknownError is a wrapper for any error related to service unavailability. | ||||||
|
||||||
| // UnavailableError UnknownError is a wrapper for any error related to service unavailability. | |
| // UnavailableError is a wrapper for any error related to service unavailability. |
Copilot
AI
Jan 20, 2026
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.
The variable naming uses 'u' as the receiver for BadRequestError and NotImplementedError, but this is inconsistent. The letter 'u' suggests 'unavailable' which was used for UnavailableError. Consider using 'b' for BadRequestError and 'n' for NotImplementedError for clarity.
Uh oh!
There was an error while loading. Please reload this page.