From 9ce7a531f25a0be531a520b9eb451965c77cbf68 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 7 Dec 2021 15:55:23 +0100 Subject: [PATCH] unknown database tag exception introduced --- DbService.cs | 17 ++++++++++++----- serviceErrorCodes.yaml | 5 +++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/DbService.cs b/DbService.cs index 9fe8fc6..711f0a5 100644 --- a/DbService.cs +++ b/DbService.cs @@ -28,6 +28,9 @@ namespace com.krohne.genericdatabaseapiservice.Services { public string Name { get; set; } } + public class DbInfoServiceException : Exception {} + public class UnknownDatabaseTagException: DbInfoServiceException {} + public interface IDbInfoService { DbInfoObject GetInfoByTag(string tag); string GetInfoStringByTag(string tag); @@ -44,16 +47,20 @@ namespace com.krohne.genericdatabaseapiservice.Services { } public DbInfoObject GetInfoByTag(string tag) { - return DbInfos[tag]; + try { + return DbInfos[tag]; + } catch (KeyNotFoundException) { + throw new UnknownDatabaseTagException(); + } } public string GetInfoStringByTag(string tag) { return String.Format( "Server={0};User ID={1};Password={2};Database={3}", - DbInfos[tag].Host, - DbInfos[tag].User, - DbInfos[tag].Password, - DbInfos[tag].Name); + GetInfoByTag(tag).Host, + GetInfoByTag(tag).User, + GetInfoByTag(tag).Password, + GetInfoByTag(tag).Name); } } diff --git a/serviceErrorCodes.yaml b/serviceErrorCodes.yaml index 8745f24..77579e5 100644 --- a/serviceErrorCodes.yaml +++ b/serviceErrorCodes.yaml @@ -15,6 +15,11 @@ Exceptions: ServiceErrorCode: 10003 ErrorMessage: unsupported data type, review the DbService implementation 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 - Exception: Exception ErrorCode: 500