Skip to content

Commit 4475cc5

Browse files
Throw error when trying to register a handler with an id that is already registered
1 parent 5a7d723 commit 4475cc5

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/main/java/top/offsetmonkey538/meshlib/api/HttpHandlerRegistry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public interface HttpHandlerRegistry {
2424
*
2525
* @param id your handler or mod's id
2626
* @param handler the {@link HttpHandler} to be registered
27-
* @throws IllegalArgumentException when the provided id is empty
27+
* @throws IllegalArgumentException when the provided id is empty or a handler with this id is already registered
2828
* @see HttpHandler
2929
*/
3030
void register(@NotNull String id, @NotNull HttpHandler handler) throws IllegalArgumentException;

src/main/java/top/offsetmonkey538/meshlib/impl/HttpHandlerRegistryImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class HttpHandlerRegistryImpl implements HttpHandlerRegistry {
1616
@Override
1717
public void register(@NotNull String id, @NotNull HttpHandler handler) throws IllegalArgumentException {
1818
if (id.isEmpty()) throw new IllegalArgumentException("Id may not be empty!");
19+
if (handlers.containsKey(id)) throw new IllegalArgumentException("Handler with id '" + id + "' already registered!");
1920

2021
handlers.put(id, handler);
2122
}

0 commit comments

Comments
 (0)