Error Handling

If a request to the Mastodon API fails, an exception will be thrown, so it's best to add your code in a try/catch block.

The type of the exception that is thrown depends on the underlying issue. Generally if the request is received by the Mastodon server, but the server responds with an error, an instance of MastodonHttpException is thrown with some information about the error.

In other cases - eg. due to network connection issues - a number of different exception types may be thrown, so it's best to have Exception as the type of the last catch.

@using Skybrud.Social.Mastodon.Exceptions

@{

    try {

        // Make a request to the Mastodon API

    } catch (MastodonHttpException ex) {

        <pre>@ex</pre>
        <pre>@ex.StatusCode</pre>
        <pre>@ex.Error</pre>
        <pre>@ex.Response.Body</pre>

        return;

    } catch (Exception ex) {

        <pre>@ex</pre>

        return;

    }

}