error codes for schema

This commit is contained in:
mpostma 2020-05-26 12:17:53 +02:00
parent 9c58ca7ce5
commit e2546f2646
2 changed files with 10 additions and 3 deletions

View File

@ -36,6 +36,7 @@ pub enum Code {
// invalid state error
InvalidState,
MissingPrimaryKey,
PrimaryKeyAlreadyPresent,
// invalid documents FIXME make one error code?
MissingDocumentId,
@ -77,7 +78,8 @@ impl Code {
// invalid state error
InvalidState => ErrCode::internal("invalid_state", StatusCode::INTERNAL_SERVER_ERROR),
// FIXME probably not an internal statuscode there
MissingPrimaryKey => ErrCode::internal("MissingPrimaryKey", StatusCode::INTERNAL_SERVER_ERROR),
MissingPrimaryKey => ErrCode::internal("missing_primary_key", StatusCode::INTERNAL_SERVER_ERROR),
PrimaryKeyAlreadyPresent => ErrCode::internal("primary_key_already_present", StatusCode::INTERNAL_SERVER_ERROR),
// invalid document
MissingDocumentId => ErrCode::invalid("MissingDocumentId", StatusCode::BAD_REQUEST),

View File

@ -26,7 +26,12 @@ impl error::Error for Error {}
impl ErrorCode for Error {
fn error_code(&self) -> Code {
// TODO populate with correct error codes
Code::Internal
use Error::*;
match self {
FieldNameNotFound(_) => Code::Internal,
MaxFieldsLimitExceeded => Code::MaxFieldsLimitExceeded,
PrimaryKeyAlreadyPresent => Code::PrimaryKeyAlreadyPresent,
}
}
}