mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
fix(route): error not being returned
This commit is contained in:
parent
23482da259
commit
d60688c66f
1 changed files with 10 additions and 5 deletions
|
@ -59,6 +59,7 @@ type (
|
||||||
|
|
||||||
impl types.Route
|
impl types.Route
|
||||||
isValidated bool
|
isValidated bool
|
||||||
|
lastError gperr.Error
|
||||||
}
|
}
|
||||||
Routes map[string]*Route
|
Routes map[string]*Route
|
||||||
)
|
)
|
||||||
|
@ -68,9 +69,9 @@ func (r Routes) Contains(alias string) bool {
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route) Validate() (err gperr.Error) {
|
func (r *Route) Validate() gperr.Error {
|
||||||
if r.isValidated {
|
if r.isValidated {
|
||||||
return nil
|
return r.lastError
|
||||||
}
|
}
|
||||||
r.isValidated = true
|
r.isValidated = true
|
||||||
r.Finalize()
|
r.Finalize()
|
||||||
|
@ -88,6 +89,9 @@ func (r *Route) Validate() (err gperr.Error) {
|
||||||
|
|
||||||
errs := gperr.NewBuilder("entry validation failed")
|
errs := gperr.NewBuilder("entry validation failed")
|
||||||
|
|
||||||
|
var impl types.Route
|
||||||
|
var err gperr.Error
|
||||||
|
|
||||||
switch r.Scheme {
|
switch r.Scheme {
|
||||||
case types.SchemeFileServer:
|
case types.SchemeFileServer:
|
||||||
r.impl, err = NewFileServer(r)
|
r.impl, err = NewFileServer(r)
|
||||||
|
@ -115,10 +119,10 @@ func (r *Route) Validate() (err gperr.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if errs.HasError() {
|
if errs.HasError() {
|
||||||
return errs.Error()
|
r.lastError = errs.Error()
|
||||||
|
return r.lastError
|
||||||
}
|
}
|
||||||
|
|
||||||
var impl types.Route
|
|
||||||
switch r.Scheme {
|
switch r.Scheme {
|
||||||
case types.SchemeFileServer:
|
case types.SchemeFileServer:
|
||||||
impl, err = NewFileServer(r)
|
impl, err = NewFileServer(r)
|
||||||
|
@ -131,6 +135,7 @@ func (r *Route) Validate() (err gperr.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
r.lastError = err
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,7 +144,7 @@ func (r *Route) Validate() (err gperr.Error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Route) Start(parent task.Parent) (err gperr.Error) {
|
func (r *Route) Start(parent task.Parent) (err gperr.Error) {
|
||||||
if r.impl == nil {
|
if r.impl == nil { // should not happen
|
||||||
return gperr.New("route not initialized")
|
return gperr.New("route not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue