mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-14 07:18:21 +02:00
core/zero: use exit code 0 for bad requests
This commit is contained in:
parent
3fcce1d9ef
commit
6a3fdfa257
2 changed files with 22 additions and 0 deletions
|
@ -6,6 +6,8 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
|
||||||
|
@ -40,6 +42,12 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := runFn(ctx); err != nil && !errors.Is(err, context.Canceled) {
|
if err := runFn(ctx); err != nil && !errors.Is(err, context.Canceled) {
|
||||||
|
// if the error was due to a bad request, return 0 as the exit code
|
||||||
|
if strings.Contains(err.Error(), "bad request") {
|
||||||
|
log.Logger().WithLevel(zerolog.FatalLevel).Err(err).Msg("cmd/pomerium")
|
||||||
|
log.Writer.Close()
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
log.Fatal().Err(err).Msg("cmd/pomerium")
|
log.Fatal().Err(err).Msg("cmd/pomerium")
|
||||||
}
|
}
|
||||||
log.Info(ctx).Msg("cmd/pomerium: exiting")
|
log.Info(ctx).Msg("cmd/pomerium: exiting")
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"slices"
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -24,6 +25,19 @@ func (m *MultiWriter) Add(w io.Writer) {
|
||||||
m.mu.Unlock()
|
m.mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close closes the multi writer.
|
||||||
|
func (m *MultiWriter) Close() error {
|
||||||
|
var err error
|
||||||
|
m.mu.Lock()
|
||||||
|
for _, w := range m.ws {
|
||||||
|
if c, ok := w.(io.Closer); ok {
|
||||||
|
err = errors.Join(err, c.Close())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.mu.Unlock()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Remove removes a writer from the multi writer.
|
// Remove removes a writer from the multi writer.
|
||||||
func (m *MultiWriter) Remove(w io.Writer) {
|
func (m *MultiWriter) Remove(w io.Writer) {
|
||||||
m.mu.Lock()
|
m.mu.Lock()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue