Question

We are in the process of constructing an API (using WCF).

So far I noticed 2 ways in which methods could go wrong due to problems with the parameters sent.

  1. wrong format, for example we have a string date parameter which should be in a certain format, if it's in a different format the method cannot continue.
  2. if a method role is to do something identified by an ID, but that ID does not exist in the application (DB)

First we thought throwing an exception, but I realize now that this is not truly an "exceptional" situation, these kind of things is pretty common.

Right now we deal with it in the following way:

We have an abstract class which is called APIResponse. it has a boolean success variable, and an array of messages for the API's client. Each group of methods has a corresponding implementation of this class and that will be the returned object.

is this kind of approach ok?

No correct solution

Licensed under: CC-BY-SA with attribution
scroll top