From ad17abe01cb4043238709259f4b7ac8513de5160 Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L de Mello" Date: Wed, 26 Feb 2025 16:39:35 -0300 Subject: [PATCH] feat(smalltrip,exceptions): retryAfter in 503 Service Unavailable exceptionn --- smalltrip/exceptions/500.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/smalltrip/exceptions/500.go b/smalltrip/exceptions/500.go index c0f7f01..1c1c358 100644 --- a/smalltrip/exceptions/500.go +++ b/smalltrip/exceptions/500.go @@ -3,6 +3,7 @@ package exceptions import ( "errors" "net/http" + "time" ) // InternalServerError creates a new [Exception] with the "500 Internal Server Error" @@ -58,13 +59,18 @@ func BadGateway(opts ...Option) Exception { // ServiceUnavailable creates a new [Exception] with the "503 Service Unavailable" // status code, a human readable message and the provided error describing what in // the request was wrong. The severity of this Exception by default is [ERROR]. -func ServiceUnavailable(opts ...Option) Exception { +// +// A Retry-After header is passed with the duration provided by the "retryAfter" +// parameter. +func ServiceUnavailable(retryAfter time.Time, opts ...Option) Exception { o := []Option{ WithStatus(http.StatusServiceUnavailable), WithCode("Service Unavailable"), WithMessage("Not ready to handle the request."), WithError(errors.New("server is not ready to handle the request")), WithSeverity(ERROR), + + WithHeader("Retry-After", retryAfter.Format("Mon, 02 Jan 2006 15:04:05 GMT")), } o = append(o, opts...)