March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
Register NowGet certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now
Hi,
I'm getting data from a server on my LAN and I need to redirect the request to another endpoint on web in case the script found an error in the LAN endpoint.
The error that I am expecting to found in the LAN endpoint is knowed: the server is out of reach since it's not in the same LAN.
Here is the step I'm getting the issue:
---------------------------
UrlLocal = "192.168.0.1:5588/endpoint",
UrlWEB = "https://somewebcontent.net/otherendpoint ",
Response = try Web.Contents(UrlLocal) otherwise Web.Contents(UrlWEB)
[...]
---------------------------
I had try the try... otherwise clause, but the Power Query does not seens return the otherwise clause, it simply block on DataSource.Error: impossible to contact the remote host.
The Web.Contents(UrlLocal) and Web.Contents(UrlWEB) works just fine if they I use them without the try...otherwise.
Obs.: the try...otherwise also does not work if:
Response = try Web.Contents(UrlLocal) otherwise error "Custom error"
Response = try Web.Contents(UrlLocal) otherwise "anything else"
What I am possible doing wrong?
Thanks a lot!
Solved! Go to Solution.
Hi @Jeff_001
try .. otherwise (annoyingly) doesn't always flag errors even when an error has clearly occurred.
For example, if you do this with a non-existant URL
= try Web.Contents(UrlLocal)
an error occurs but the result of that step is this, showing no error, yet the Value of the record is an error.
You can trap the error by adding a subsequent step
then testing the HasError part of that record, and doing different things depending on whether HasError is true or false
= if Value[HasError] then Web.Contents(UrlWEB) else Web.Page(Value[Value])
Here's the full query
let
UrlLocal = "192.168.0.1:5588/endpoint",
UrlWEB = "https://bbc.co.uk", //"https://somewebcontent.net/otherendpoint ",
Response = try Web.Contents(UrlLocal),
Value = try Text.From(Response[Value]),
Page = if Value[HasError] then Web.Contents(UrlWEB) else Web.Page(Value[Value])
in
Page
Regards
Phil
Proud to be a Super User!
Hi @Jeff_001
try .. otherwise (annoyingly) doesn't always flag errors even when an error has clearly occurred.
For example, if you do this with a non-existant URL
= try Web.Contents(UrlLocal)
an error occurs but the result of that step is this, showing no error, yet the Value of the record is an error.
You can trap the error by adding a subsequent step
then testing the HasError part of that record, and doing different things depending on whether HasError is true or false
= if Value[HasError] then Web.Contents(UrlWEB) else Web.Page(Value[Value])
Here's the full query
let
UrlLocal = "192.168.0.1:5588/endpoint",
UrlWEB = "https://bbc.co.uk", //"https://somewebcontent.net/otherendpoint ",
Response = try Web.Contents(UrlLocal),
Value = try Text.From(Response[Value]),
Page = if Value[HasError] then Web.Contents(UrlWEB) else Web.Page(Value[Value])
in
Page
Regards
Phil
Proud to be a Super User!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
Check out the November 2024 Power BI update to learn about new features.
User | Count |
---|---|
60 | |
53 | |
26 | |
17 | |
17 |