Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
- improved error handling
Browse files Browse the repository at this point in the history
- RR_BROADCAST_URL renamed to RR_BROADCAST_PATH
  • Loading branch information
wolfy-j committed Dec 9, 2019
1 parent dc8a206 commit 3820273
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 2 additions & 3 deletions access_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ func (w *accessValidator) Error() string {
// case of error
func (w *accessValidator) assertServerAccess(f http.HandlerFunc, r *http.Request) error {
if err := attributes.Set(r, "ws:joinServer", true); err != nil {
// return err
// todo: need to update it
return err
}

defer delete(attributes.All(r), "ws:joinServer")
Expand All @@ -87,7 +86,7 @@ func (w *accessValidator) assertServerAccess(f http.HandlerFunc, r *http.Request
// the decision to authorize user will be based on response code (200).
func (w *accessValidator) assertTopicsAccess(f http.HandlerFunc, r *http.Request, channels ...string) error {
if err := attributes.Set(r, "ws:joinTopics", strings.Join(channels, ",")); err != nil {
return w
return err
}

defer delete(attributes.All(r), "ws:joinTopics")
Expand Down
8 changes: 6 additions & 2 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (s *Service) Init(

if env != nil {
// ensure that underlying kernel knows what route to handle
env.SetEnv("RR_BROADCAST_URL", cfg.Path)
env.SetEnv("RR_BROADCAST_PATH", cfg.Path)
}

// init all this stuff
Expand Down Expand Up @@ -97,7 +97,11 @@ func (s *Service) middleware(f http.HandlerFunc) http.HandlerFunc {
// checking server access
if err := newValidator().assertServerAccess(f, r); err != nil {
// show the error to the user
err.(*accessValidator).copy(w)
if av, ok := err.(*accessValidator); ok {
av.copy(w)
} else {
w.WriteHeader(400)
}
return
}

Expand Down
2 changes: 1 addition & 1 deletion tests/worker-ok.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
while ($req = $psr7->acceptRequest()) {
try {
$resp = new \Zend\Diactoros\Response();
$resp->getBody()->write($_SERVER['RR_BROADCAST_URL'] ?? '');
$resp->getBody()->write($_SERVER['RR_BROADCAST_PATH'] ?? '');
$psr7->respond($resp);
} catch (\Throwable $e) {
$psr7->getWorker()->error((string)$e);
Expand Down

0 comments on commit 3820273

Please sign in to comment.