vweb: add custom errors (#9519)
parent
28018c6fc9
commit
e9c7cd0c9f
|
@ -69,6 +69,16 @@ pub:
|
||||||
data string
|
data string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct UnexpectedExtraAttributeError {
|
||||||
|
msg string
|
||||||
|
code int
|
||||||
|
}
|
||||||
|
|
||||||
|
struct MultiplePathAttributesError {
|
||||||
|
msg string = 'Expected at most one path attribute'
|
||||||
|
code int
|
||||||
|
}
|
||||||
|
|
||||||
// declaring init_once in your App struct is optional
|
// declaring init_once in your App struct is optional
|
||||||
pub fn (ctx Context) init_once() {}
|
pub fn (ctx Context) init_once() {}
|
||||||
|
|
||||||
|
@ -467,7 +477,7 @@ fn parse_attrs(name string, attrs []string) ?([]http.Method, string) {
|
||||||
}
|
}
|
||||||
if attr.starts_with('/') {
|
if attr.starts_with('/') {
|
||||||
if path != '' {
|
if path != '' {
|
||||||
return error('Expected at most one path attribute')
|
return IError(&MultiplePathAttributesError{})
|
||||||
}
|
}
|
||||||
path = attr
|
path = attr
|
||||||
x.delete(i)
|
x.delete(i)
|
||||||
|
@ -476,7 +486,9 @@ fn parse_attrs(name string, attrs []string) ?([]http.Method, string) {
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
if x.len > 0 {
|
if x.len > 0 {
|
||||||
return error('Encountered unexpected extra attributes: $x')
|
return IError(&UnexpectedExtraAttributeError{
|
||||||
|
msg: 'Encountered unexpected extra attributes: $x'
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if methods.len == 0 {
|
if methods.len == 0 {
|
||||||
methods = [http.Method.get]
|
methods = [http.Method.get]
|
||||||
|
|
Loading…
Reference in New Issue