diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-01-13 07:07:16 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-01-13 07:07:16 +0000 |
commit | f18e7f6920590ee6f2e59be508518b70a4611638 (patch) | |
tree | 2f80c427e740c2c6f7f2a47be2b869b6d9847e58 /service/http/config.go | |
parent | 5dc83ef5eee77f4d1ef557e5f8b566e75892680d (diff) | |
parent | bbfcd4fb6eb138c616dab01ea610fbf6ed15985b (diff) |
Merge #472
472: feat(http): Distinct app and internal error codes in the handleError function r=48d90782 a=48d90782
This PR introduces distinct error codes for the app and internal RR errors.
Errors:
```go
roadrunner.ErrNoAssociatedPool
roadrunner.ErrAllocateWorker
roadrunner.ErrWorkerNotReady
roadrunner.ErrEmptyPayload
roadrunner.ErrPoolStopped
roadrunner.ErrWorkerAllocateTimeout
roadrunner.ErrAllWorkersAreDead
```
now associated with the internal error codes. All other errors are application errors.
Some types of errors are impossible to distinguish in the RR1, for example `json.Unmarshall` internal error or similar.
The `.rr.yaml` now contain two more options for the errors.
```yaml
http:
internalErrorCode: 502,
appErrorCode: 502
```
Default behavior unchanged (500 error code as before), but now might be overridden.
closes #471
Co-authored-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'service/http/config.go')
-rw-r--r-- | service/http/config.go | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/service/http/config.go b/service/http/config.go index 00f61652..34733e44 100644 --- a/service/http/config.go +++ b/service/http/config.go @@ -3,15 +3,21 @@ package http import ( "errors" "fmt" - "github.com/spiral/roadrunner" - "github.com/spiral/roadrunner/service" "net" + "net/http" "os" "strings" + + "github.com/spiral/roadrunner" + "github.com/spiral/roadrunner/service" ) // Config configures RoadRunner HTTP server. type Config struct { + // AppErrorCode is error code for the application errors (default 500) + AppErrorCode uint64 + // Error code for the RR pool or worker errors + InternalErrorCode uint64 // Port and port to handle as http server. Address string @@ -60,7 +66,6 @@ type HTTP2Config struct { func (cfg *HTTP2Config) InitDefaults() error { cfg.Enabled = true cfg.MaxConcurrentStreams = 128 - return nil } @@ -109,6 +114,14 @@ func (c *Config) EnableFCGI() bool { // Hydrate must populate Config values using given Config source. Must return error if Config is not valid. func (c *Config) Hydrate(cfg service.Config) error { + if c.AppErrorCode == 0 { + // set default behaviour - 500 error code + c.AppErrorCode = http.StatusInternalServerError + } + if c.InternalErrorCode == 0 { + // set default behaviour - 500 error code + c.InternalErrorCode = http.StatusInternalServerError + } if c.Workers == nil { c.Workers = &roadrunner.ServerConfig{} } |