Contact me!
Eric Håård
+46 (0) 73 375 86 06

Errors

There are two kinds of exceptions that the API will throw. Basically they are of the same type, FaultException, but with different messages: “Bad Request” (400) or “Internal Server Error” (500).

API Client with Non WCF REST endpoint

Bad Requests contain messages that can be shown to the end users while Internal Server Error does not. These exceptions are logged in the back-end and can be view from the API Reference.

When catching faults from the API use a catch like this:

try
{
    // make call to the API.
}
catch (FaultException<ErrorMessage> ex)
{
    if(ex.Message == "Bad Request")
    {
        // Display message to end user.
    }
    else
    {
        // Display some generic fault message
    }
}

When processing Bad Requests use the ex.Detail to get the information sent by the API. ex.Detail is of type ErrorMessage and its Record-property will contain a Messages list of faults when returned from the API. The list is a Key-Value dictionary where the Key in the list is a constant representing the text (Value) and can be hard coded against. Where as the Value will be the Storm Commerce fault text.

In order to handle different faults in a custom way do as follows when dealing with Bad Requests:

var message = ex.Detail.Message;
var messages = ex.Detail.Messages; // To get the dictionary
if (messages.ContainsKey("QuotationMissing")
{
    message += " " + messages["QuotationMissing"];
    // Or append a costom message for Quotation missing
}
// Check other Names if required.
// Display message to user.

REST-ish

When used with a WCF REST endpoint a WebFaultException will be thrown. Otherwise all above applies.

Fault names

Here are links to all fault names and what value they return for all languages that are available.

English

Swedish

German

French

Spanish

Italian