-
Notifications
You must be signed in to change notification settings - Fork 338
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(api): add api initialization notice #4869
Conversation
pkg/api/router.go
Outdated
s.router = mux.NewRouter() | ||
s.router.NotFoundHandler = http.HandlerFunc(jsonhttp.NotFoundHandler) | ||
// WithFullAPI will enable all available endpoints, because some endpoints are not available during syncing. | ||
func WithFullAPI() MountOption { |
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.
why have an option if we can explicitly enable the the full API using EnableFullAPI()
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.
Initial idea to provide options is for unit testing purposes. Was considering to add WithFullAPIDisabled
option as well. And then expand testServerOptions
in api_test.go.
Also it can be used in one line to mount and enable apiService.Mount(api.WithFullAPI())
, which is the case in devnode.go
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.
Option is removed
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!
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.
👏
Checklist
Description
This PR addresses issue #4734 by improving the behavior of the Bee API during the node initialization process. Previously, when the node was syncing batch data, the API appeared to be inaccessible, providing no indication of the ongoing sync process. Now, all routes are mounted immediately, but some may be temporarily disabled during initialization, returning appropriate status codes.
Changes
503 Service Unavailable: Routes that are disabled during the syncing phase now return a
503 Service Unavailable
status with the message:"Node is syncing. This endpoint is unavailable. Try again later."
Once the syncing is complete, the routes will be enabled and respond normally.
501 Not Implemented: If the
swapEnabled
orchequebookEnabled
flags are set tofalse
, routes that depend on these features will now return a501 Not Implemented
status.404 Not Found: Any routes that do not exist will return a
404 Not Found
status.Open API Spec Version Changes (if applicable)
Motivation and Context (Optional)
This change improves the user experience by providing clear feedback during node initialization, preventing confusion when the API appears to be inaccessible. It ensures that users are informed about the node's state and can understand why certain API routes may not be available temporarily.
How it works
503
until they are enabled once the sync is complete.501
if the corresponding feature is disabled.404
as expected.Related Issue (Optional)
#4734
Screenshots (if appropriate):