Bug 37893: (QA follow-up): Check if port already in use when storing a listener
To test: 1) Ensure a port is already in use in the server 2) Try creating a new listener using that same port. 3) Notice the error 'Something went wrong: Error: Can't listen on port 127.0.0.1:8023/tcp/IPv4. Port already in use.' is shown on the UI Co-authored-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com> Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
ee62bd459e
commit
2ed892b38c
|
|
@ -108,6 +108,12 @@ sub add {
|
|||
openapi => { error => "Given " . $to_api_mapping->{ $_->parameter } . " does not exist" }
|
||||
);
|
||||
}
|
||||
elsif ( $_->isa('Koha::Exceptions::ObjectNotCreated') ) {
|
||||
return $c->render(
|
||||
status => 500,
|
||||
openapi => { error => $_->error }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$c->unhandled_exception($_);
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ use Modern::Perl;
|
|||
|
||||
use base qw(Koha::Object);
|
||||
|
||||
use IO::Socket;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Koha::SIP2::Listener- Koha Sip Listener Object class
|
||||
|
|
@ -29,6 +31,34 @@ Koha::SIP2::Listener- Koha Sip Listener Object class
|
|||
|
||||
=cut
|
||||
|
||||
=head3 store
|
||||
|
||||
store
|
||||
|
||||
=cut
|
||||
|
||||
sub store {
|
||||
my ($self) = @_;
|
||||
|
||||
my ($port) = $self->port =~ /:(\d+)/;
|
||||
my ($addr) = $self->port =~ /([0-9.]+)/;
|
||||
|
||||
my $socket = IO::Socket::INET->new(
|
||||
LocalAddr => $addr,
|
||||
LocalPort => $port,
|
||||
Proto => 'tcp',
|
||||
ReuseAddr => 0,
|
||||
Listen => 1
|
||||
);
|
||||
|
||||
unless ($socket) {
|
||||
Koha::Exceptions::ObjectNotCreated->throw(
|
||||
error => "Can't listen on port " . $self->port . ". Port already in use." );
|
||||
}
|
||||
|
||||
return $self->SUPER::store;
|
||||
}
|
||||
|
||||
=head3 get_for_config
|
||||
|
||||
Returns the listener hashref as expected by C4/SIP/Sip/Configuration->new;
|
||||
|
|
|
|||
Loading…
Reference in New Issue