vweb: add custom errors (#9519)

pull/9536/head
Atakan Yenel 2021-03-30 14:30:16 +02:00 committed by GitHub
parent 28018c6fc9
commit e9c7cd0c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -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]