Abhishek Pandey 757007e027
Skip graph call if the download url has expired (#4419)
<!-- PR description-->

Builds on top of earlier PR #4417 to skip graph API call if the token has already expired. This is a performance optimization.

---

#### Does this PR need a docs update or release note?

- [x]  Yes, it's included
- [ ] 🕐 Yes, but in a later PR
- [ ]  No

#### Type of change

<!--- Please check the type of change your PR introduces: --->
- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [ ] 🧹 Tech Debt/Cleanup
- [x] Performance Opt

#### Issue(s)

<!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. -->
* internal

#### Test Plan

<!-- How will this be tested prior to merging.-->
- [ ] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
2023-10-09 13:42:54 +00:00

28 lines
555 B
Go

package common
import (
"net/url"
"github.com/alcionai/clues"
)
// GetQueryParamFromURL parses an URL and returns value of the specified
// query parameter. In case of multiple occurrences, first one is returned.
func GetQueryParamFromURL(
rawURL, queryParam string,
) (string, error) {
u, err := url.Parse(rawURL)
if err != nil {
return "", clues.Wrap(err, "parsing url")
}
qp := u.Query()
val := qp.Get(queryParam)
if len(val) == 0 {
return "", clues.New("query param not found").With("query_param", queryParam)
}
return val, nil
}