FIX code review

This commit is contained in:
Jasder 2020-11-10 18:18:08 +08:00
parent cc19783651
commit b5d3f32d68
3 changed files with 4 additions and 22 deletions

View File

@ -131,7 +131,6 @@ class Gitea::ClientService < ApplicationService
{status: 200} {status: 200}
end end
when 401 when 401
""
raise Error, mark + "401" raise Error, mark + "401"
when 422 when 422
result = JSON.parse(response&.body) result = JSON.parse(response&.body)
@ -147,6 +146,8 @@ class Gitea::ClientService < ApplicationService
raise Error, mark + message raise Error, mark + message
when 403 when 403
{status: 403, message: '你没有权限操作!'} {status: 403, message: '你没有权限操作!'}
when 404
{status: 404, message: '你访问的链接不存在!'}
else else
if response&.body.blank? if response&.body.blank?
message = "请求失败" message = "请求失败"

View File

@ -15,7 +15,7 @@ class Gitea::Repository::Commits::CompareService < Gitea::ClientService
def call def call
response = get(url, params) response = get(url, params)
render_result(response) render_status(response)
end end
private private
@ -26,13 +26,4 @@ class Gitea::Repository::Commits::CompareService < Gitea::ClientService
def url def url
"/repos/#{owner}/#{repo}/compare/#{base}...#{head}".freeze "/repos/#{owner}/#{repo}/compare/#{base}...#{head}".freeze
end end
def render_result(response)
case response.status
when 200
JSON.parse(response.body)
else
{status: -1, message: "#{body['message']}"}
end
end
end end

View File

@ -15,7 +15,7 @@ class Gitea::Repository::Commits::GetService < Gitea::ClientService
def call def call
response = get(url, params) response = get(url, params)
render_result(response) render_status(response)
end end
private private
@ -32,14 +32,4 @@ class Gitea::Repository::Commits::GetService < Gitea::ClientService
"/repos/#{owner}/#{repo}/git/commits/#{sha}".freeze "/repos/#{owner}/#{repo}/git/commits/#{sha}".freeze
end end
end end
def render_result(response)
body = JSON.parse(response.body)
case response.status
when 200
JSON.parse(response.body)
else
{status: -1, message: "#{body['message']}"}
end
end
end end