Skip to content

Switch Case On Interpreting UnityWebRequest #2

@EliCDavis

Description

@EliCDavis

It'd be ideal to replace code like this:

public void Interpret(UnityWebRequest req) {
  if (req.responseCode == 200)
  {
      success = JsonUtility.FromJson<LocationConfiguration>(req.downloadHandler.text);
  }
  else if (req.responseCode == 400)
  {
      badRequest = JsonUtility.FromJson<ErrorMessage>(req.downloadHandler.text);
  }
  else if (req.responseCode == 401)
  {
      unauthorized = JsonUtility.FromJson<ErrorMessage>(req.downloadHandler.text);
  }
  else if (req.responseCode == 403)
  {
      forbidden = JsonUtility.FromJson<ErrorMessage>(req.downloadHandler.text);
  }
  else if (req.responseCode == 404)
  {
      notFound = JsonUtility.FromJson<ErrorMessage>(req.downloadHandler.text);
  }
  else if (req.responseCode == 500)
  {
      internalServerError = JsonUtility.FromJson<ErrorMessage>(req.downloadHandler.text);
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions