Allow RepositoryResolver to throw ServiceMayNotContinueException
Implementations may want to send an error message to the user, which doesn't really fit with any of the existing exception types. ServiceMayNotContinueException, on the other hand, is documented as always containing a user-visible error string, so use that. Modify the git and HTTP transport mechanisms to properly relay this message to the end user. Change-Id: I362e67ea46102a145bf2c6284d38788537c9735f
This commit is contained in:
parent
d794a4fde3
commit
55bf06b43d
|
@ -65,6 +65,7 @@
|
|||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.transport.ServiceMayNotContinueException;
|
||||
import org.eclipse.jgit.transport.resolver.RepositoryResolver;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotAuthorizedException;
|
||||
import org.eclipse.jgit.transport.resolver.ServiceNotEnabledException;
|
||||
|
@ -141,6 +142,9 @@ public void doFilter(final ServletRequest request,
|
|||
} catch (ServiceNotAuthorizedException e) {
|
||||
res.sendError(SC_UNAUTHORIZED);
|
||||
return;
|
||||
} catch (ServiceMayNotContinueException e) {
|
||||
sendError(req, res, SC_INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
return;
|
||||
}
|
||||
try {
|
||||
request.setAttribute(ATTRIBUTE_REPOSITORY, db);
|
||||
|
|
|
@ -366,7 +366,8 @@ synchronized DaemonService matchService(final String cmd) {
|
|||
return null;
|
||||
}
|
||||
|
||||
Repository openRepository(DaemonClient client, String name) {
|
||||
Repository openRepository(DaemonClient client, String name)
|
||||
throws ServiceMayNotContinueException {
|
||||
// Assume any attempt to use \ was by a Windows client
|
||||
// and correct to the more typical / used in Git URIs.
|
||||
//
|
||||
|
|
|
@ -130,7 +130,16 @@ void execute(final DaemonClient client, final String commandLine)
|
|||
throws IOException, ServiceNotEnabledException,
|
||||
ServiceNotAuthorizedException {
|
||||
final String name = commandLine.substring(command.length() + 1);
|
||||
Repository db = client.getDaemon().openRepository(client, name);
|
||||
Repository db;
|
||||
try {
|
||||
db = client.getDaemon().openRepository(client, name);
|
||||
} catch (ServiceMayNotContinueException e) {
|
||||
// An error when opening the repo means the client is expecting a ref
|
||||
// advertisement, so use that style of error.
|
||||
PacketLineOut pktOut = new PacketLineOut(client.getOutputStream());
|
||||
pktOut.writeString("ERR " + e.getMessage() + "\n");
|
||||
db = null;
|
||||
}
|
||||
if (db == null)
|
||||
return;
|
||||
try {
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.transport.ServiceMayNotContinueException;
|
||||
|
||||
/**
|
||||
* Locate a Git {@link Repository} by name from the URL.
|
||||
|
@ -82,7 +83,12 @@ public Repository open(Object req, String name)
|
|||
* @throws ServiceNotEnabledException
|
||||
* the repository may exist, but HTTP access is not allowed on the
|
||||
* target repository, for the current user.
|
||||
* @throws ServiceMayNotContinueException
|
||||
* the repository may exist, but HTTP access is not allowed for
|
||||
* the current request. The exception message contains a detailed
|
||||
* message that should be shown to the user.
|
||||
*/
|
||||
Repository open(C req, String name) throws RepositoryNotFoundException,
|
||||
ServiceNotAuthorizedException, ServiceNotEnabledException;
|
||||
ServiceNotAuthorizedException, ServiceNotEnabledException,
|
||||
ServiceMayNotContinueException;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue