Skip to content

Commit

Permalink
fix: job request errors are handled
Browse files Browse the repository at this point in the history
Fixes #147
  • Loading branch information
marisademeglio committed Sep 29, 2023
1 parent cf1ddc1 commit 72a8566
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/main/data/apis/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import fetch, { Response, RequestInit } from 'node-fetch'

import { info, error } from 'electron-log'
import { jobResponseXmlToJson } from 'shared/parser/pipelineXmlConverter/jobResponseToJson'

/**
* Create a fetch function on the pipeline webservice
Expand Down Expand Up @@ -90,7 +91,7 @@ export const pipelineAPI = {
launchJob: (j: Job) =>
createPipelineFetchFunction(
(ws) => `${baseurl(ws)}/jobs`,
(text) => jobXmlToJson(text),
(text) => jobResponseXmlToJson(text),
{
method: 'POST',
body: jobRequestToXml({
Expand Down
14 changes: 13 additions & 1 deletion src/renderer/components/JobDetailsPane/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ import { readableStatus } from 'shared/jobName'
const { App } = window

export function JobDetailsPane({ job }) {
return (
return job.jobData.type == 'JobRequestError' ? (
<>
<h1>Error</h1>
<p>{job.jobData.description}</p>
<button
onClick={(e) => {
App.store.dispatch(removeJob(job))
}}
>
Close job
</button>
</>
) : (
<>
<section
className="header"
Expand Down
16 changes: 16 additions & 0 deletions src/shared/parser/pipelineXmlConverter/errorToJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { JobRequestError } from 'shared/types'
import { parseXml } from './parser'

function errorXmlToJson(xmlString: string): JobRequestError {
let errorElm = parseXml(xmlString, 'error')
let descElms = errorElm.getElementsByTagName('description')
let traceElms = errorElm.getElementsByTagName('trace')

return {
type: 'JobRequestError',
description: descElms.length > 0 ? descElms[0].textContent?.trim() : '',
trace: traceElms.length > 0 ? traceElms[0].textContent?.trim() : '',
}
}

export { errorXmlToJson }
21 changes: 21 additions & 0 deletions src/shared/parser/pipelineXmlConverter/jobResponseToJson.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// a job response could be <job...> or <error... >
// find out which one

import { errorXmlToJson } from './errorToJson'
import { jobXmlToJson } from './jobToJson'
import { sniffRoot } from './parser'

function jobResponseXmlToJson(xmlString: string) {
let rootElm = sniffRoot(xmlString)
if (rootElm == 'error') {
return errorXmlToJson(xmlString)
}
else if (rootElm == 'job') {
return jobXmlToJson(xmlString)
}
else {
return {error: true, description: "Unrecognized response"}
}
}

export { jobResponseXmlToJson }
2 changes: 1 addition & 1 deletion src/shared/parser/pipelineXmlConverter/voiceToJson.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Voice } from 'shared/types/pipeline'
import { Voice } from 'shared/types'

function voiceElementToJson(voiceElm: Element): Voice {
let voice: Voice = {
Expand Down
10 changes: 9 additions & 1 deletion src/shared/types/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Voice } from "./ttsConfig"
import { Voice } from './ttsConfig'

/**
* Webservice connexion data to compute url for fetch:
Expand Down Expand Up @@ -231,6 +231,7 @@ export type Job = {
}
// JobData is the JSON representation of Pipeline WS data for a single job
export type JobData = {
type: 'JobRequestSuccess'
jobId: string // the ID from the pipeline
priority?: Priority
status?: JobStatus
Expand All @@ -250,6 +251,13 @@ export type JobData = {
href: string
}

// thrown by the pipeline when a job request could not be processed
export type JobRequestError = {
type: 'JobRequestError'
description?: string
trace?: string
}

export enum JobState {
NEW,
SUBMITTED,
Expand Down

0 comments on commit 72a8566

Please sign in to comment.