-
Notifications
You must be signed in to change notification settings - Fork 286
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
036b5e7
commit 0730c2e
Showing
11 changed files
with
203 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package capture | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pingcap/errors" | ||
cerror "github.com/pingcap/tiflow/pkg/errors" | ||
) | ||
|
||
// httpBadRequestError is some errors that will cause a BadRequestError in http handler | ||
var httpBadRequestError = []*errors.Error{ | ||
cerror.ErrAPIInvalidParam, cerror.ErrSinkURIInvalid, cerror.ErrStartTsBeforeGC, | ||
cerror.ErrChangeFeedNotExists, cerror.ErrTargetTsBeforeStartTs, cerror.ErrTableIneligible, | ||
cerror.ErrFilterRuleInvalid, cerror.ErrChangefeedUpdateRefused, cerror.ErrMySQLConnectionError, | ||
cerror.ErrMySQLInvalidConfig, | ||
} | ||
|
||
// IsHTTPBadRequestError check if a error is a http bad request error | ||
func IsHTTPBadRequestError(err error) bool { | ||
if err == nil { | ||
return false | ||
} | ||
for _, e := range httpBadRequestError { | ||
if e.Equal(err) { | ||
return true | ||
} | ||
|
||
rfcCode, ok := cerror.RFCCode(err) | ||
if ok && e.RFCCode() == rfcCode { | ||
return true | ||
} | ||
|
||
if strings.Contains(err.Error(), string(e.RFCCode())) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2021 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package capture | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pingcap/errors" | ||
cerror "github.com/pingcap/tiflow/pkg/errors" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestIsHTTPBadRequestError(t *testing.T) { | ||
err := cerror.ErrAPIInvalidParam.GenWithStack("aa") | ||
require.Equal(t, true, IsHTTPBadRequestError(err)) | ||
err = cerror.ErrAPIInvalidParam.Wrap(errors.New("aa")) | ||
require.Equal(t, true, IsHTTPBadRequestError(err)) | ||
err = cerror.ErrPDEtcdAPIError.GenWithStack("aa") | ||
require.Equal(t, false, IsHTTPBadRequestError(err)) | ||
err = nil | ||
require.Equal(t, false, IsHTTPBadRequestError(err)) | ||
} |
Oops, something went wrong.