Skip to content

Commit

Permalink
Optimized: Error Msg
Browse files Browse the repository at this point in the history
  • Loading branch information
jitwxs committed Apr 18, 2020
1 parent 524d6f3 commit ad0fe82
Showing 1 changed file with 33 additions and 27 deletions.
60 changes: 33 additions & 27 deletions WindowsFormsApp1/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ public HttpStatus GetSongBasicInfo(string jsonStr, ref Song song)

if (httpStatus.GetCode() == HTTP_STATUS_SUCCESS)
{
JToken songName = obj["songs"][0]["name"];
if (songName != null)
{
song.SetName(songName.ToString());
try
{
JToken songName = obj["songs"][0]["name"];
if (songName != null)
{
song.SetName(songName.ToString());
}
else
{
return new HttpStatus(HTTP_STATUS_NOT_FOUND, "歌曲不存在");
}
}
else
catch (Exception ew)
{
Console.WriteLine("歌曲名为空");
return new HttpStatus(HTTP_STATUS_NOT_FOUND, "歌曲不存在");
}

try
Expand All @@ -80,7 +87,7 @@ public HttpStatus GetSongBasicInfo(string jsonStr, ref Song song)
}
catch (Exception ew)
{
Console.WriteLine("获取歌曲信息错误:" + ew.StackTrace);
return new HttpStatus(HTTP_STATUS_NOT_FOUND, "歌曲不存在");
}
}

Expand All @@ -95,24 +102,23 @@ public HttpStatus GetSongLrc(string jsonStr, ref Song song)

if (httpStatus.GetCode() == HTTP_STATUS_SUCCESS)
{
JToken lyric = obj["lrc"]["lyric"];
if (lyric != null)
{
song.SetLyric(lyric.ToString());
}
else
{
Console.WriteLine("歌词为空");
}

JToken tlyric = obj["tlyric"]["lyric"];
if (tlyric != null)
{
song.SetTlyric(tlyric.ToString());
}
else
{
Console.WriteLine("译文歌词为空");
try
{
JToken lyric = obj["lrc"]["lyric"];
if (lyric != null)
{
song.SetLyric(lyric.ToString());
}

JToken tlyric = obj["tlyric"]["lyric"];
if (tlyric != null)
{
song.SetTlyric(tlyric.ToString());
}
}
catch(Exception ew)
{
return new HttpStatus(HTTP_STATUS_NOT_FOUND, "歌词不存在");
}
}

Expand Down Expand Up @@ -458,7 +464,7 @@ private void searchBtn_Click(object sender, EventArgs e)
HttpStatus status = GetSongLrc(HttpHelper(lrc_url), ref song);
if (status.GetCode() != HTTP_STATUS_SUCCESS)
{
MessageBox.Show("获取歌词失败,错误信息" + status.GetMsg(), "异常");
MessageBox.Show("搜索失败" + status.GetMsg(), "异常");
return;
}

Expand All @@ -477,7 +483,7 @@ private void searchBtn_Click(object sender, EventArgs e)
status = GetSongBasicInfo(HttpHelper(song_url), ref song);
if (status.GetCode() != HTTP_STATUS_SUCCESS)
{
MessageBox.Show("请求歌曲信息失败,错误信息" + status.GetMsg(), "异常");
MessageBox.Show("搜索失败" + status.GetMsg(), "异常");
return;
}

Expand Down

0 comments on commit ad0fe82

Please sign in to comment.