Merge branch 'master' of ssh://repo.hottis.de:2922/wolutator/genericdatabaseapiservice

This commit is contained in:
2021-12-08 14:54:17 +01:00
2 changed files with 17 additions and 5 deletions

View File

@ -28,6 +28,9 @@ namespace com.krohne.genericdatabaseapiservice.Services {
public string Name { get; set; } public string Name { get; set; }
} }
public class DbInfoServiceException : Exception {}
public class UnknownDatabaseTagException: DbInfoServiceException {}
public interface IDbInfoService { public interface IDbInfoService {
DbInfoObject GetInfoByTag(string tag); DbInfoObject GetInfoByTag(string tag);
string GetInfoStringByTag(string tag); string GetInfoStringByTag(string tag);
@ -44,16 +47,20 @@ namespace com.krohne.genericdatabaseapiservice.Services {
} }
public DbInfoObject GetInfoByTag(string tag) { public DbInfoObject GetInfoByTag(string tag) {
try {
return DbInfos[tag]; return DbInfos[tag];
} catch (KeyNotFoundException) {
throw new UnknownDatabaseTagException();
}
} }
public string GetInfoStringByTag(string tag) { public string GetInfoStringByTag(string tag) {
return String.Format( return String.Format(
"Server={0};User ID={1};Password={2};Database={3}", "Server={0};User ID={1};Password={2};Database={3}",
DbInfos[tag].Host, GetInfoByTag(tag).Host,
DbInfos[tag].User, GetInfoByTag(tag).User,
DbInfos[tag].Password, GetInfoByTag(tag).Password,
DbInfos[tag].Name); GetInfoByTag(tag).Name);
} }
} }

View File

@ -15,6 +15,11 @@ Exceptions:
ServiceErrorCode: 10003 ServiceErrorCode: 10003
ErrorMessage: unsupported data type, review the DbService implementation ErrorMessage: unsupported data type, review the DbService implementation
ErrorInfoURL: https://google.com ErrorInfoURL: https://google.com
- Exception: UnknownDatabaseTagException
ErrorCode: 500
ServiceErrorCode: 10004
ErrorMessage: the database tag mentioned in the API spec is not configured on the server, review the server configuration
ErrorInfoURL: https://google.com
# Make sure "Exception: Exception" is the last entry in the list # Make sure "Exception: Exception" is the last entry in the list
- Exception: Exception - Exception: Exception
ErrorCode: 500 ErrorCode: 500