Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Access to Resource is Forbidden - Error Handling

Hi there. Below is a shortened version of the code I'm having problems with. 

 

let
    Source = Json.Document(Web.Contents("https://statdata.pgatour.com/r/004/2020/leaderboard-v2.json?userTrackingId=exp=0579883146~acl=*~hmac=e4a005fec9674e17425005689e8c5fa8d2f8d6f28492c400cdfbd4988a2163c5")),
  
    ErrorHandling = try Source otherwise null
in
    Source

 

In the full code the tracking id does update so it doesn't return an error but I want to ensure that if the tracking id doesn't update, it does not crash/stop refreshing. Normal error handling doesn't seem to capture the "access to this source is forbidden". Any suggestions?

 

Thanks 

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

exactly. The Web.Contents status handling can't be retrieved by error handling. You have to gor for the Web.Contents-responses meta data to retrieve the status code. Using it's result to understand whether it was okay or not. Try out this code to understand how it works

let
    response = Web.Contents(
        "https://api.census.gov/data/2018/pep/population?get=POP&for=states", 
        [
            ManualStatusHandling = {400,401,403,404,429,500,503}
        ]
    ),
    responseMetadata = Value.Metadata(response),
    responseCode = responseMetadata[Response.Status]
in
    responseCode


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

2 REPLIES 2
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

exactly. The Web.Contents status handling can't be retrieved by error handling. You have to gor for the Web.Contents-responses meta data to retrieve the status code. Using it's result to understand whether it was okay or not. Try out this code to understand how it works

let
    response = Web.Contents(
        "https://api.census.gov/data/2018/pep/population?get=POP&for=states", 
        [
            ManualStatusHandling = {400,401,403,404,429,500,503}
        ]
    ),
    responseMetadata = Value.Metadata(response),
    responseCode = responseMetadata[Response.Status]
in
    responseCode


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Anonymous
Not applicable

ah I see, very clever! Should be able to make that work thanks!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors