1 package ch
.cyberduck
.core
.openstack
;
4 * Copyright (c) 2013 David Kocher. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * Bug fixes, suggestions and comments should be sent to:
18 * feedback@cyberduck.ch
21 import ch
.cyberduck
.core
.AbstractExceptionMappingService
;
22 import ch
.cyberduck
.core
.exception
.AccessDeniedException
;
23 import ch
.cyberduck
.core
.exception
.BackgroundException
;
24 import ch
.cyberduck
.core
.exception
.InteroperabilityException
;
25 import ch
.cyberduck
.core
.exception
.LoginFailureException
;
26 import ch
.cyberduck
.core
.exception
.NotfoundException
;
28 import org
.apache
.http
.HttpStatus
;
29 import org
.apache
.http
.StatusLine
;
31 import ch
.iterate
.openstack
.swift
.exception
.GenericException
;
36 public class SwiftExceptionMappingService
extends AbstractExceptionMappingService
<GenericException
> {
39 public BackgroundException
map(final GenericException e
) {
40 final StringBuilder buffer
= new StringBuilder();
41 this.append(buffer
, e
.getMessage());
42 final StatusLine status
= e
.getHttpStatusLine();
44 this.append(buffer
, String
.format("%d %s", status
.getStatusCode(), status
.getReasonPhrase()));
46 if(e
.getHttpStatusCode() == HttpStatus
.SC_UNAUTHORIZED
) {
47 return new LoginFailureException(buffer
.toString(), e
);
49 if(e
.getHttpStatusCode() == HttpStatus
.SC_FORBIDDEN
) {
50 return new AccessDeniedException(buffer
.toString(), e
);
52 if(e
.getHttpStatusCode() == HttpStatus
.SC_NOT_FOUND
) {
53 return new NotfoundException(buffer
.toString(), e
);
55 if(e
.getHttpStatusCode() == HttpStatus
.SC_BAD_REQUEST
) {
56 return new InteroperabilityException(buffer
.toString(), e
);
58 if(e
.getHttpStatusCode() == HttpStatus
.SC_METHOD_NOT_ALLOWED
) {
59 return new InteroperabilityException(buffer
.toString(), e
);
61 if(e
.getHttpStatusCode() == HttpStatus
.SC_NOT_IMPLEMENTED
) {
62 return new InteroperabilityException(buffer
.toString(), e
);
64 if(e
.getHttpStatusCode() == HttpStatus
.SC_CONFLICT
) {
65 return new InteroperabilityException(buffer
.toString(), e
);
67 return this.wrap(e
, buffer
);