title: Realtime Database error retrieval - Unity3D
body: <h2><strong>Scenario</strong>:</h2>
  
  <p>Need to know the type of error when an exception is present. I wasn't able to find a proper reference. </p>
  
  <h2><strong>Sources</strong>:</h2>
  
  <ul>
  <li><a href="https://firebase.google.com/docs/reference/unity/class/firebase/database/database-error" rel="nofollow noreferrer">Firebase Database Error Documentation</a></li>
  </ul>
  
  <h2><strong>Code</strong></h2>
  
  <p>Getting raw value from the database</p>
  
  <pre><code>string _error = string.Empty;
  await RootDB.Child(_node).GetValueAsync()
     .ContinueWith(
     (_task) =&gt;
     {
         if (_task.Exception != null)
         {
             Debug.Log("Exception Found in " + _node + " | " + _task.Exception.Message);
             _error = CloudErrorHandle.DatabaseErrorMessageFor(_task.Exception.InnerExceptions);
         }
         else if (_task.IsCanceled == true)
         {
             Debug.Log(_node + " | is canceled ");
         }
         else if (_task.IsFaulted == true)
         {
             Debug.Log(_node + " | is Faulted ");
         }
         else if (_task.IsCompleted == true)
         {
             Debug.Log(_node + "| is Completed");
             DataSnapshot _snapShot = _task.Result;
             if (_snapShot.Exists == true)
             {
                // Get the value _snapShot.GetRawJsonValue();
             }
             else
             {
                  Debug.Log("Snapshot DOES NOT Exist for " + _node);
             }
         }
    });
  </code></pre>
  
  <p>// From CloudErrorHandle</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>internal static string DatabaseErrorMessageFor(System.Collections.ObjectModel.ReadOnlyCollection&lt;System.Exception&gt; _innerExceptions)
  {//https://stackoverflow.com/questions/53036083/google-firebase-how-to-catch-specific-auth-exception-errors-unity
      string _errorMessage = "None";
      for (int _i = 0; _i &lt; _innerExceptions.Count; _i++)
      {
          FirebaseException _firebaseEx = _innerExceptions[_i] as FirebaseException;
          _errorMessage =  GetDatabaseExceptionForThisID(_firebaseEx.ErrorCode);
      }
      return _errorMessage;
  }
  
  internal static string GetDatabaseExceptionForThisID(int _identification)
  { //https://firebase.google.com/docs/reference/unity/class/firebase/database/database-error
      string _error = "Unknown";
      switch(_identification)
      {
          case -4:
              _error = "Disconnected";
              break;
          case -6:
              _error = "ExpiredToken";
              break;
          case -7:
              _error = "InvalidToken";
              break;
          case -8:
              _error = "MaxRetries";
              break;
          case -24:
              _error = "NetworkError";
              break;
          case -2:
              _error = "OperationFailed";
              break;
          case -9:
              _error = "OverriddenBySet";
              break;
          case -3:
              _error = "PermissionDenied";
              break;
          case -10:
              _error = "Unavailable";
              break;
          case -999:
              _error = "UnknownError";
              break;
          case -11:
              _error = "UserCodeException";
              break;
          case -25:
              _error = "WriteCanceled";
              break;
  
      }
      return _error;
  }</code></pre>
  </div>
  </div>
  </p>
  
  <h2>Request</h2>
  
  <ol>
  <li>Is it the right way to obtain the error when there is an exception?</li>
  <li>Will there be multiple errors as 'InnerExceptions' is being iterated?</li>
  <li>I am under the understanding that when there is any issue while interacting with RL-database, the exception would <strong>never</strong> be null</li>
  </ol>
  
  <p>Thank you</p>