Remove error handling in the parse_query_result method of

MangaDex::Job, and pass the possible exceptions to the frontend and
handle them there.
This commit is contained in:
Alex Ling 2020-03-03 02:33:32 +00:00
parent 7575785c1c
commit e2d01f7eb9
3 changed files with 32 additions and 25 deletions

View File

@ -91,6 +91,10 @@ const load = () => {
dataType: 'json' dataType: 'json'
}) })
.done(data => { .done(data => {
if (!data.success && data.error) {
alert('danger', `Failed to fetch download queue. Error: ${data.error}`);
return;
}
console.log(data); console.log(data);
const btnText = data.paused ? "Resume download" : "Pause download"; const btnText = data.paused ? "Resume download" : "Pause download";
$('#pause-resume-btn').text(btnText); $('#pause-resume-btn').text(btnText);

View File

@ -33,30 +33,25 @@ module MangaDex
property time : Time property time : Time
def parse_query_result(res : DB::ResultSet) def parse_query_result(res : DB::ResultSet)
begin @id = res.read String
@id = res.read String @manga_id = res.read String
@manga_id = res.read String @title = res.read String
@title = res.read String @manga_title = res.read String
@manga_title = res.read String status = res.read Int32
status = res.read Int32 @status_message = res.read String
@status_message = res.read String @pages = res.read Int32
@pages = res.read Int32 @success_count = res.read Int32
@success_count = res.read Int32 @fail_count = res.read Int32
@fail_count = res.read Int32 time = res.read Int64
time = res.read Int64 @status = JobStatus.new status
@status = JobStatus.new status @time = Time.unix_ms time
@time = Time.unix_ms time
return true
rescue e
puts e
return false
end
end end
# Raises if the result set does not contain the correct set of columns
def self.from_query_result(res : DB::ResultSet) def self.from_query_result(res : DB::ResultSet)
job = Job.allocate job = Job.allocate
success = job.parse_query_result res job.parse_query_result res
return success ? job : nil return job
end end
def initialize(@id, @manga_id, @title, @manga_title, @status, @time) def initialize(@id, @manga_id, @title, @manga_title, @status, @time)

View File

@ -128,11 +128,19 @@ class APIRouter < Router
end end
get "/api/admin/mangadex/queue" do |env| get "/api/admin/mangadex/queue" do |env|
jobs = @context.queue.get_all begin
send_json env, { jobs = @context.queue.get_all
"jobs" => jobs, send_json env, {
"paused" => @context.queue.paused? "jobs" => jobs,
}.to_json "paused" => @context.queue.paused?,
"success" => true
}.to_json
rescue e
send_json env, {
"success" => false,
"error" => e.message
}.to_json
end
end end
post "/api/admin/mangadex/queue/delete/:id" do |env| post "/api/admin/mangadex/queue/delete/:id" do |env|