api/v2: Delete silence respond with 404 when silence is not found (#3352)
Signed-off-by: Emmanuel Lodovice <lodovice@amazon.com>
This commit is contained in:
parent
fe287e504e
commit
263ca5c943
|
@ -634,6 +634,9 @@ func (api *API) deleteSilenceHandler(params silence_ops.DeleteSilenceParams) mid
|
|||
sid := params.SilenceID.String()
|
||||
if err := api.silences.Expire(sid); err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to expire silence", "err", err)
|
||||
if err == silence.ErrNotFound {
|
||||
return silence_ops.NewDeleteSilenceNotFound()
|
||||
}
|
||||
return silence_ops.NewDeleteSilenceInternalServerError().WithPayload(err.Error())
|
||||
}
|
||||
return silence_ops.NewDeleteSilenceOK()
|
||||
|
|
|
@ -178,7 +178,7 @@ func TestDeleteSilenceHandler(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
"unknownSid",
|
||||
500,
|
||||
404,
|
||||
},
|
||||
{
|
||||
unexpiredSid,
|
||||
|
|
|
@ -41,6 +41,12 @@ func (o *DeleteSilenceReader) ReadResponse(response runtime.ClientResponse, cons
|
|||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
case 404:
|
||||
result := NewDeleteSilenceNotFound()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, result
|
||||
case 500:
|
||||
result := NewDeleteSilenceInternalServerError()
|
||||
if err := result.readResponse(response, consumer, o.formats); err != nil {
|
||||
|
@ -103,6 +109,57 @@ func (o *DeleteSilenceOK) readResponse(response runtime.ClientResponse, consumer
|
|||
return nil
|
||||
}
|
||||
|
||||
// NewDeleteSilenceNotFound creates a DeleteSilenceNotFound with default headers values
|
||||
func NewDeleteSilenceNotFound() *DeleteSilenceNotFound {
|
||||
return &DeleteSilenceNotFound{}
|
||||
}
|
||||
|
||||
/*
|
||||
DeleteSilenceNotFound describes a response with status code 404, with default header values.
|
||||
|
||||
A silence with the specified ID was not found
|
||||
*/
|
||||
type DeleteSilenceNotFound struct {
|
||||
}
|
||||
|
||||
// IsSuccess returns true when this delete silence not found response has a 2xx status code
|
||||
func (o *DeleteSilenceNotFound) IsSuccess() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsRedirect returns true when this delete silence not found response has a 3xx status code
|
||||
func (o *DeleteSilenceNotFound) IsRedirect() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsClientError returns true when this delete silence not found response has a 4xx status code
|
||||
func (o *DeleteSilenceNotFound) IsClientError() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// IsServerError returns true when this delete silence not found response has a 5xx status code
|
||||
func (o *DeleteSilenceNotFound) IsServerError() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCode returns true when this delete silence not found response a status code equal to that given
|
||||
func (o *DeleteSilenceNotFound) IsCode(code int) bool {
|
||||
return code == 404
|
||||
}
|
||||
|
||||
func (o *DeleteSilenceNotFound) Error() string {
|
||||
return fmt.Sprintf("[DELETE /silence/{silenceID}][%d] deleteSilenceNotFound ", 404)
|
||||
}
|
||||
|
||||
func (o *DeleteSilenceNotFound) String() string {
|
||||
return fmt.Sprintf("[DELETE /silence/{silenceID}][%d] deleteSilenceNotFound ", 404)
|
||||
}
|
||||
|
||||
func (o *DeleteSilenceNotFound) readResponse(response runtime.ClientResponse, consumer runtime.Consumer, formats strfmt.Registry) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewDeleteSilenceInternalServerError creates a DeleteSilenceInternalServerError with default headers values
|
||||
func NewDeleteSilenceInternalServerError() *DeleteSilenceInternalServerError {
|
||||
return &DeleteSilenceInternalServerError{}
|
||||
|
|
|
@ -127,6 +127,8 @@ paths:
|
|||
responses:
|
||||
'200':
|
||||
description: Delete silence response
|
||||
'404':
|
||||
description: A silence with the specified ID was not found
|
||||
'500':
|
||||
$ref: '#/responses/InternalServerError'
|
||||
/alerts:
|
||||
|
|
|
@ -272,6 +272,9 @@ func init() {
|
|||
"200": {
|
||||
"description": "Delete silence response"
|
||||
},
|
||||
"404": {
|
||||
"description": "A silence with the specified ID was not found"
|
||||
},
|
||||
"500": {
|
||||
"$ref": "#/responses/InternalServerError"
|
||||
}
|
||||
|
@ -1077,6 +1080,9 @@ func init() {
|
|||
"200": {
|
||||
"description": "Delete silence response"
|
||||
},
|
||||
"404": {
|
||||
"description": "A silence with the specified ID was not found"
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal server error",
|
||||
"schema": {
|
||||
|
|
|
@ -50,6 +50,31 @@ func (o *DeleteSilenceOK) WriteResponse(rw http.ResponseWriter, producer runtime
|
|||
rw.WriteHeader(200)
|
||||
}
|
||||
|
||||
// DeleteSilenceNotFoundCode is the HTTP code returned for type DeleteSilenceNotFound
|
||||
const DeleteSilenceNotFoundCode int = 404
|
||||
|
||||
/*
|
||||
DeleteSilenceNotFound A silence with the specified ID was not found
|
||||
|
||||
swagger:response deleteSilenceNotFound
|
||||
*/
|
||||
type DeleteSilenceNotFound struct {
|
||||
}
|
||||
|
||||
// NewDeleteSilenceNotFound creates DeleteSilenceNotFound with default headers values
|
||||
func NewDeleteSilenceNotFound() *DeleteSilenceNotFound {
|
||||
|
||||
return &DeleteSilenceNotFound{}
|
||||
}
|
||||
|
||||
// WriteResponse to the client
|
||||
func (o *DeleteSilenceNotFound) WriteResponse(rw http.ResponseWriter, producer runtime.Producer) {
|
||||
|
||||
rw.Header().Del(runtime.HeaderContentType) //Remove Content-Type on empty responses
|
||||
|
||||
rw.WriteHeader(404)
|
||||
}
|
||||
|
||||
// DeleteSilenceInternalServerErrorCode is the HTTP code returned for type DeleteSilenceInternalServerError
|
||||
const DeleteSilenceInternalServerErrorCode int = 500
|
||||
|
||||
|
|
Loading…
Reference in New Issue