1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

net and http: more consistent error messages

This commit is contained in:
Delyan Angelov
2019-11-12 18:23:53 +02:00
committed by Alexander Medvednikov
parent 35741b46bd
commit 32473eeafe
5 changed files with 31 additions and 31 deletions

View File

@@ -56,7 +56,7 @@ pub fn post(url, data string) ?Response {
pub fn new_request(typ, _url, _data string) ?Request {
if _url == '' {
return error('bad url')
return error('http.new_request: empty url')
}
mut url := _url
mut data := _data
@@ -125,7 +125,7 @@ pub fn (req &Request) do() ?Response {
for key, val in req.headers {
//h := '$key: $val'
}
url := urllib.parse(req.url) or { return error('http.request.do: invalid URL $req.url') }
url := urllib.parse(req.url) or { return error('http.request.do: invalid URL "$req.url"') }
mut rurl := url
mut resp := Response{}
mut no_redirects := 0
@@ -136,7 +136,7 @@ pub fn (req &Request) do() ?Response {
if ! (resp.status_code in [301, 302, 303, 307, 308]) { break }
// follow any redirects
redirect_url := resp.headers['Location']
qrurl := urllib.parse( redirect_url ) or { return error('http.request.do: invalid URL in redirect $redirect_url') }
qrurl := urllib.parse( redirect_url ) or { return error('http.request.do: invalid URL in redirect "$redirect_url"') }
rurl = qrurl
no_redirects++
}
@@ -167,7 +167,7 @@ fn (req &Request) method_and_url_to_response(method string, url net_dot_urllib.U
}
return res
}
return error('http.request.do: unsupported scheme: $scheme')
return error('http.request.method_and_url_to_response: unsupported scheme: "$scheme"')
}
fn parse_response(resp string) Response {

View File

@@ -13,7 +13,7 @@ fn (req &Request) http_do(port int, method, host_name, path string) ?Response {
client.send( s.str, s.len ) or {}
for {
readbytes := client.crecv( rbuffer, bufsize )
if readbytes < 0 { return error('http_do error reading response. readbytes: $readbytes') }
if readbytes < 0 { return error('http.request.http_do: error reading response. readbytes=$readbytes') }
if readbytes == 0 { break }
sb.write( tos(rbuffer, readbytes) )
}