title: Best practice for handling API errors with angular translate
body: <p>I have an API &lt;> SPA architecture.</p>
  
  <p>But I don't know exactly where to put translations, specially when errors are send.</p>
  
  <p>I would prefer to just have translated text (i18n etc) at my angular app. The API should only send out english texts.</p>
  
  <p>But I don't know how to</p>
  
  <p>Imagine an Error message like this: (nodejs+restify)</p>
  
  <pre><code>server.get('/api/', function (req, res, next) {
      return next(new server.errors.UnauthorizedError('You are not authorized'));
  });
  </code></pre>
  
  <p>This will send a 401 with json in body.</p>
  
  <p>If the API only speaks english, how can I translate it at best at the SPA?</p>
  
  <p>How can I put this to, one of these translation approaches:</p>
  
  <p><code>&lt;span&gt;{{message | translate}}&lt;/span&gt;</code></p>
  
  <p>or</p>
  
  <p><code>&lt;span&gt;{{lang.message}}&lt;/span&gt;</code></p>
  
  <p>Of course I use the $translateProvider at Angular and have a locate files with translation in it.</p>
  
  <p>Is there no other way by sending language keys? Like this:</p>
  
  <pre><code>server.get('/api/', function (req, res, next) {
      return next(new server.errors.UnauthorizedError('NOT_AUTHORIZED_ERROR'));
  });
  </code></pre>
  
  <p>With this I could have a locate-en.json file like:</p>
  
  <pre><code>{
      errors: {
          NOT_AUTHORIZED_ERROR: "You are not authorized"
      }
  }
  </code></pre>
  
  <p>I find this kind of uncommon.</p>