title: How do I add errors to my Spring MVC REST Service?
body: <p>How can I change/update the following REST call from Spring MVC to return a error if the user did not enter of the the two names I was coding for.. something like a <em>not found</em>?</p>
  <pre><code>@RequestMapping(value = &quot;/{name}&quot;, method = RequestMethod.GET)
  @ResponseBody
  public User getName(@PathVariable String name, ModelMap model)
  {
      logger.debug(&quot;I am in the controller and got user name: &quot; + name);
  
      /*
          Simulate a successful lookup for two users. This
          is where your real lookup code would go.
       */
  
      if (&quot;name2&quot;.equals(name))
      {
          return new User(&quot;real name 2&quot;, name);
      }
  
      if (&quot;name1&quot;.equals(name))
      {
          return new User(&quot;real name 1&quot;, name);
      }
  
      return null;
  }
  </code></pre>