-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWebContents ⁞ Catch uncatchable Datasource errors┐main_query.pq
87 lines (81 loc) · 2.47 KB
/
WebContents ⁞ Catch uncatchable Datasource errors┐main_query.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// WebRequest
let
/*
About:
Without ManualStatusHandling, you can't catch exceptions thrown by Web.Contents.
Try appears to work, it says [HasError] is false.
(try Expression)[HasError]
but [Value] always resolves as an exception (that's not caught by you)
*/
tests = {
[
Label = "Base",
Response =
Web.Contents( "https://catfact.ninja", [ RelativePath = "breeds"] )
],
[
Label = "Uncatchable",
Response =
try Web.Contents( "https://httpbin.org",
[ RelativePath = "/status/codes/418" ] )
catch (e) =>
"Error, but we caught it" meta e[Message]
],
[
Label = "Invalid Operator",
Response =
try 1 > "a" * 4
catch (e) =>
"Error, but we caught it" meta e
],
[
Label = "Catchable Web",
Response =
try Web.Contents( "https://httpbin.org",
[ RelativePath = "/status/codes/418" ] )
catch (e) =>
"Error, but we caught it" meta e
],
[
Label = "Catchable Web using StatusHandling",
Response =
try Web.Contents( "https://httpbin.org",
[ RelativePath = "/status/codes/418",
ManualStatusHandling =
{401, 402, 404} & {405..500}
] )
catch (e) =>
"Error, but we caught it" meta e
]
},
Summary = Table.FromRecords(
tests,
type table[
Label = text,
Response = nullable binary
],
MissingField.Error),
col_json = Table.AddColumn(
Summary, "Json",
(row) =>
try
Json.Document( row[Response] , TextEncoding.Utf8 )
catch (e) =>
null meta [Exception = e],
type nullable record
),
col_text = Table.AddColumn(
col_json, "Response as Raw Text",
(row) =>
Text.FromBinary( row[Response], TextEncoding.Utf8 ),
type text
),
error_text = Table.AddColumn(
col_text, "Error Message",
(row) =>
if row[Response] <> null
then Value.Metadata( row[Response] ) else null,
type nullable record
)
in
col_text