traefikerrorreplace

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

README

Status Code/Error Replacer

Code Coverage Code Analysis Codacy Security Scan Go Report Card Build and Test Source Static Analysis Integration Test

Some apps become unhappy when they receive unexpected error codes, such as when Traefik can't find an available server.

This plugin solves this issue by filtering and replacing problematic error codes with ones the app won't complain about.

Configuration

Configuration documentation

Supported configurations per body

Setting Allowed values Required Description
matchStatus []int Yes List of status codes to match
replaceStatus int Yes Status code to replace with
debug bool No Enables extra debug logging
Enable the plugin
experimental:
  plugins:
    traefikerrorreplace:
      modulename: github.com/PseudoResonance/traefikerrorreplace
      version: v1.0.1
Plugin configuration
http:
  middlewares:
    traefikerrorreplace:
      plugin:
        traefikerrorreplace:
          matchStatus:
            - 500
            - 503
          replaceStatus: 404

  routers:
    my-router:
      rule: Path(`/whoami`)
      service: service-whoami
      entryPoints:
        - http
      middlewares:
        - traefikerrorreplace

  services:
    service-whoami:
      loadBalancer:
        servers:
          - url: http://127.0.0.1:5000

Testing

https://github.com/PseudoResonance/traefikerrorreplace/tree/master/test

We have written the following tests in this repo:

  • golang linting
  • yaegi tests (validate configuration matches what Traefik expects)
  • General GO code coverage
  • Virtual implementation tests (spin up traefik with yml/toml tests to make sure the plugin actually works)
  • Live implementation tests (spin up traefik with the plugin definition as it would be for you, and run the same tests again)

These tests allow us to make sure the plugin is always functional with Traefik and Traefik version updates.

Documentation

Overview

Package traefikerrorreplace Traefik Plugin.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(_ context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New created a new plugin.

Types

type Config

type Config struct {
	Debug         bool  `json:"debug,omitempty"`
	MatchStatus   []int `json:"matchStatus,omitempty"`
	ReplaceStatus int   `json:"replaceStatus,omitempty"`
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

type StatusCodeReplacer

type StatusCodeReplacer struct {
	// contains filtered or unexported fields
}

StatusCodeReplacer is a plugin that replaces status codes.

func (*StatusCodeReplacer) ServeHTTP

func (r *StatusCodeReplacer) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL