refactor: improve error interceptor

This commit is contained in:
Jonas Kaninda
2024-11-14 00:26:21 +01:00
parent 328703ad79
commit 42abf56473
15 changed files with 284 additions and 185 deletions

View File

@@ -18,6 +18,7 @@ limitations under the License.
import (
"fmt"
"github.com/jkaninda/goma-gateway/internal/middleware"
error_interceptor "github.com/jkaninda/goma-gateway/pkg/error-interceptor"
"github.com/jkaninda/goma-gateway/pkg/logger"
"github.com/jkaninda/goma-gateway/util"
"golang.org/x/oauth2"
@@ -27,6 +28,7 @@ import (
"golang.org/x/oauth2/gitlab"
"golang.org/x/oauth2/google"
"gopkg.in/yaml.v3"
"net/http"
"os"
)
@@ -180,11 +182,24 @@ func initConfig(configFile string) error {
Middlewares: []string{"basic-auth", "api-forbidden-paths"},
},
{
Path: "/",
Name: "Hostname and load balancing example",
Hosts: []string{"example.com", "example.localhost"},
InterceptErrors: []int{404, 405, 500},
RateLimit: 60,
Path: "/",
Name: "Hostname and load balancing example",
Hosts: []string{"example.com", "example.localhost"},
//InterceptErrors: []int{404, 405, 500},
ErrorInterceptor: error_interceptor.ErrorInterceptor{
ContentType: applicationJson,
Errors: []error_interceptor.Error{
{
Code: http.StatusUnauthorized,
Message: http.StatusText(http.StatusUnauthorized),
},
{
Code: http.StatusInternalServerError,
Message: http.StatusText(http.StatusInternalServerError),
},
},
},
RateLimit: 60,
Backends: []string{
"https://example.com",
"https://example2.com",