Bug 1396831 - Improve readability of error_code and http_status. r=jgraham

No semantic changes.

MozReview-Commit-ID: F4TJI2i5bJo

--HG--
extra : rebase_source : 703abf5278a7cf46393f9b720cea6e0948a5c1dd
This commit is contained in:
Andreas Tolfsen 2017-09-05 14:39:32 +01:00
Родитель 0875bd29d9
Коммит 88efb4d67b
1 изменённых файлов: 61 добавлений и 58 удалений

Просмотреть файл

@ -144,70 +144,73 @@ pub enum ErrorStatus {
impl ErrorStatus {
pub fn error_code(&self) -> &'static str {
use self::ErrorStatus::*;
match *self {
ErrorStatus::ElementClickIntercepted => "element click intercepted",
ErrorStatus::ElementNotInteractable => "element not interactable",
ErrorStatus::ElementNotSelectable => "element not selectable",
ErrorStatus::InsecureCertificate => "insecure certificate",
ErrorStatus::InvalidArgument => "invalid argument",
ErrorStatus::InvalidCookieDomain => "invalid cookie domain",
ErrorStatus::InvalidCoordinates => "invalid coordinates",
ErrorStatus::InvalidElementState => "invalid element state",
ErrorStatus::InvalidSelector => "invalid selector",
ErrorStatus::InvalidSessionId => "invalid session id",
ErrorStatus::JavascriptError => "javascript error",
ErrorStatus::MoveTargetOutOfBounds => "move target out of bounds",
ErrorStatus::NoSuchAlert => "no such alert",
ErrorStatus::NoSuchCookie => "no such cookie",
ErrorStatus::NoSuchElement => "no such element",
ErrorStatus::NoSuchFrame => "no such frame",
ErrorStatus::NoSuchWindow => "no such window",
ErrorStatus::ScriptTimeout => "script timeout",
ErrorStatus::SessionNotCreated => "session not created",
ErrorStatus::StaleElementReference => "stale element reference",
ErrorStatus::Timeout => "timeout",
ErrorStatus::UnableToCaptureScreen => "unable to capture screen",
ErrorStatus::UnableToSetCookie => "unable to set cookie",
ErrorStatus::UnexpectedAlertOpen => "unexpected alert open",
ErrorStatus::UnknownCommand |
ErrorStatus::UnknownError => "unknown error",
ErrorStatus::UnknownMethod => "unknown method",
ErrorStatus::UnknownPath => "unknown command",
ErrorStatus::UnsupportedOperation => "unsupported operation",
ElementClickIntercepted => "element click intercepted",
ElementNotInteractable => "element not interactable",
ElementNotSelectable => "element not selectable",
InsecureCertificate => "insecure certificate",
InvalidArgument => "invalid argument",
InvalidCookieDomain => "invalid cookie domain",
InvalidCoordinates => "invalid coordinates",
InvalidElementState => "invalid element state",
InvalidSelector => "invalid selector",
InvalidSessionId => "invalid session id",
JavascriptError => "javascript error",
MoveTargetOutOfBounds => "move target out of bounds",
NoSuchAlert => "no such alert",
NoSuchCookie => "no such cookie",
NoSuchElement => "no such element",
NoSuchFrame => "no such frame",
NoSuchWindow => "no such window",
ScriptTimeout => "script timeout",
SessionNotCreated => "session not created",
StaleElementReference => "stale element reference",
Timeout => "timeout",
UnableToCaptureScreen => "unable to capture screen",
UnableToSetCookie => "unable to set cookie",
UnexpectedAlertOpen => "unexpected alert open",
UnknownCommand |
UnknownError => "unknown error",
UnknownMethod => "unknown method",
UnknownPath => "unknown command",
UnsupportedOperation => "unsupported operation",
}
}
pub fn http_status(&self) -> StatusCode {
use self::ErrorStatus::*;
use self::StatusCode::*;
match *self {
ErrorStatus::ElementClickIntercepted => StatusCode::BadRequest,
ErrorStatus::ElementNotInteractable => StatusCode::BadRequest,
ErrorStatus::ElementNotSelectable => StatusCode::BadRequest,
ErrorStatus::InsecureCertificate => StatusCode::BadRequest,
ErrorStatus::InvalidArgument => StatusCode::BadRequest,
ErrorStatus::InvalidCookieDomain => StatusCode::BadRequest,
ErrorStatus::InvalidCoordinates => StatusCode::BadRequest,
ErrorStatus::InvalidElementState => StatusCode::BadRequest,
ErrorStatus::InvalidSelector => StatusCode::BadRequest,
ErrorStatus::InvalidSessionId => StatusCode::NotFound,
ErrorStatus::JavascriptError => StatusCode::InternalServerError,
ErrorStatus::MoveTargetOutOfBounds => StatusCode::InternalServerError,
ErrorStatus::NoSuchAlert => StatusCode::BadRequest,
ErrorStatus::NoSuchCookie => StatusCode::NotFound,
ErrorStatus::NoSuchElement => StatusCode::NotFound,
ErrorStatus::NoSuchFrame => StatusCode::BadRequest,
ErrorStatus::NoSuchWindow => StatusCode::BadRequest,
ErrorStatus::ScriptTimeout => StatusCode::RequestTimeout,
ErrorStatus::SessionNotCreated => StatusCode::InternalServerError,
ErrorStatus::StaleElementReference => StatusCode::BadRequest,
ErrorStatus::Timeout => StatusCode::RequestTimeout,
ErrorStatus::UnableToCaptureScreen => StatusCode::BadRequest,
ErrorStatus::UnableToSetCookie => StatusCode::InternalServerError,
ErrorStatus::UnexpectedAlertOpen => StatusCode::InternalServerError,
ErrorStatus::UnknownCommand => StatusCode::NotFound,
ErrorStatus::UnknownError => StatusCode::InternalServerError,
ErrorStatus::UnknownMethod => StatusCode::MethodNotAllowed,
ErrorStatus::UnknownPath => StatusCode::NotFound,
ErrorStatus::UnsupportedOperation => StatusCode::InternalServerError,
ElementClickIntercepted => BadRequest,
ElementNotInteractable => BadRequest,
ElementNotSelectable => BadRequest,
InsecureCertificate => BadRequest,
InvalidArgument => BadRequest,
InvalidCookieDomain => BadRequest,
InvalidCoordinates => BadRequest,
InvalidElementState => BadRequest,
InvalidSelector => BadRequest,
InvalidSessionId => NotFound,
JavascriptError => InternalServerError,
MoveTargetOutOfBounds => InternalServerError,
NoSuchAlert => BadRequest,
NoSuchCookie => NotFound,
NoSuchElement => NotFound,
NoSuchFrame => BadRequest,
NoSuchWindow => BadRequest,
ScriptTimeout => RequestTimeout,
SessionNotCreated => InternalServerError,
StaleElementReference => BadRequest,
Timeout => RequestTimeout,
UnableToCaptureScreen => BadRequest,
UnableToSetCookie => InternalServerError,
UnexpectedAlertOpen => InternalServerError,
UnknownCommand => NotFound,
UnknownError => InternalServerError,
UnknownMethod => MethodNotAllowed,
UnknownPath => NotFound,
UnsupportedOperation => InternalServerError,
}
}
}