-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(daemon): add ErrorResponse to allow external error creation (#303)
#265 provides the ability for the daemon REST API to be extended by appending new handlers to the API list. For example, the following new reboot command can be added now: // requestReboot asks the daemon to gracefully shut down the system // and issue a reboot. func requestReboot(d *daemon.Daemon) daemon.Response { d.HandleRestart(restart.RestartSystem) result := deviceResult{} return daemon.SyncResponse(result) } Note that SyncResponse was already public, which allows the code above to work. Following this patch, we can now reply with a suitable error response: : switch(...) { case reboot: requestReboot(...) default: return daemon.ErrorResponse(http.StatusBadRequest,"invalid media type %q", mediaType) { :
- Loading branch information
Showing
3 changed files
with
49 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters