Skip to content

Commit ea3b591

Browse files
committed
Revert latest changes
1 parent dd07d18 commit ea3b591

File tree

2 files changed

+11
-14
lines changed

2 files changed

+11
-14
lines changed

models/url_handler.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,16 @@ func GetURLHandlerInstance() LinkHandlerInterface {
2323

2424
// Handle - using scrap lib, check the link status
2525
func (handler *urlHandler) Handle(linkPath string) int {
26-
respStatus, err := handler.scrap(linkPath, true)
26+
respStatus, err := handler.scrap(linkPath)
2727
for i := 0; i < 2 && err != nil; i++ {
2828
errLower := strings.ToLower(err.Error())
29-
respStatus, err = handler.scrap(linkPath, false)
30-
if err == nil {
31-
return respStatus
29+
if strings.Contains(errLower, "eof") || strings.Contains(errLower, "timeout") {
30+
respStatus, err = handler.scrap(linkPath)
31+
if err == nil {
32+
return respStatus
33+
}
34+
errLower = strings.ToLower(err.Error())
3235
}
33-
errLower = strings.ToLower(err.Error())
3436
if strings.Contains(errLower, "not found") {
3537
return 404
3638
}
@@ -48,13 +50,8 @@ func (handler *urlHandler) Handle(linkPath string) int {
4850
return respStatus
4951
}
5052

51-
func (handler *urlHandler) respStatusOK(restStatus int) bool {
52-
return restStatus >= 200 && restStatus < 300 || restStatus >= 400 && restStatus < 500
53-
}
54-
55-
func (handler *urlHandler) scrap(linkPath string, checkHead bool) (int, error) {
53+
func (handler *urlHandler) scrap(linkPath string) (int, error) {
5654
c := colly.NewCollector()
57-
c.CheckHead = checkHead
5855
respStatus := 0
5956
c.OnResponse(func(resp *colly.Response) {
6057
respStatus = resp.StatusCode

tests/integration_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ func TestFilesWithError(t *testing.T) {
2424
assert.ErrorContains(t, res, "ERROR: 3 links check failed, please check the logs")
2525
logFileContent := readLogFile(logFilePath)
2626
assert.Contains(t, logFileContent, "Went through 2 files")
27-
assert.Contains(t, logFileContent, "Line: 21 link: nla.go status: 400")
28-
assert.Contains(t, logFileContent, "Line: 33 link: source-control/merge-strategies.md status: 400")
29-
assert.Contains(t, logFileContent, "Line: 33 link: resources/templates/CONTRIBUTING.md status: 400")
27+
assert.Contains(t, logFileContent, "Line 21 link nla.go status 400")
28+
assert.Contains(t, logFileContent, "Line 33 link source-control/merge-strategies.md status 400")
29+
assert.Contains(t, logFileContent, "Line 33 link resources/templates/CONTRIBUTING.md status 400")
3030
assert.NotContains(t, logFileContent, "http://bla.com/")
3131
assert.NotContains(t, logFileContent, "http://test.com/")
3232

0 commit comments

Comments
 (0)