@@ -34,6 +34,7 @@ import {
3434 CasparCGStatusCode ,
3535 DeviceStatusDetail ,
3636 DeviceStatusInput ,
37+ CasparCGActionErrorCode ,
3738} from 'timeline-state-resolver-types'
3839import { createCasparCGStatusDetail } from './messages.js'
3940
@@ -633,17 +634,29 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
633634 if ( ! this . _ccg ?. connected ) {
634635 return {
635636 result : ActionExecutionResultCode . Error ,
636- response : t ( 'Cannot restart CasparCG without a connection' ) ,
637+ code : CasparCGActionErrorCode . CLEAR_NO_CONNECTION ,
638+ context : { } ,
639+ response : t ( 'Cannot clear CasparCG channels: no connection' ) ,
637640 }
638641 }
639642
640643 const { error, request } = await this . _ccg . executeCommand ( { command : Commands . Info , params : { } } )
641644 if ( error ) {
642- return { result : ActionExecutionResultCode . Error }
645+ return {
646+ result : ActionExecutionResultCode . Error ,
647+ code : CasparCGActionErrorCode . CLEAR_INFO_FAILED ,
648+ context : { } ,
649+ response : t ( 'Cannot clear CasparCG channels: failed to get channel info' ) ,
650+ }
643651 }
644652 const response = await request
645653 if ( ! response ?. data [ 0 ] ) {
646- return { result : ActionExecutionResultCode . Error }
654+ return {
655+ result : ActionExecutionResultCode . Error ,
656+ code : CasparCGActionErrorCode . CLEAR_NO_CHANNELS ,
657+ context : { } ,
658+ response : t ( 'Cannot clear CasparCG channels: no channels found' ) ,
659+ }
647660 }
648661
649662 await Promise . all (
@@ -697,18 +710,35 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
697710 */
698711 private async restartCasparCG ( ) : Promise < ActionExecutionResult > {
699712 if ( ! this . initOptions ) {
700- return { result : ActionExecutionResultCode . Error , response : t ( 'CasparCGDevice._connectionOptions is not set!' ) }
713+ return {
714+ result : ActionExecutionResultCode . Error ,
715+ code : CasparCGActionErrorCode . RESTART_NOT_INITIALIZED ,
716+ context : { } ,
717+ response : t ( 'Cannot restart CasparCG: device not initialized' ) ,
718+ }
701719 }
702720 if ( ! this . initOptions . launcherHost ) {
703- return { result : ActionExecutionResultCode . Error , response : t ( 'CasparCGDevice: config.launcherHost is not set!' ) }
721+ return {
722+ result : ActionExecutionResultCode . Error ,
723+ code : CasparCGActionErrorCode . RESTART_LAUNCHER_HOST_NOT_SET ,
724+ context : { } ,
725+ response : t ( 'Cannot restart CasparCG: launcher host not configured' ) ,
726+ }
704727 }
705728 if ( ! this . initOptions . launcherPort ) {
706- return { result : ActionExecutionResultCode . Error , response : t ( 'CasparCGDevice: config.launcherPort is not set!' ) }
729+ return {
730+ result : ActionExecutionResultCode . Error ,
731+ code : CasparCGActionErrorCode . RESTART_LAUNCHER_PORT_NOT_SET ,
732+ context : { } ,
733+ response : t ( 'Cannot restart CasparCG: launcher port not configured' ) ,
734+ }
707735 }
708736 if ( ! this . initOptions . launcherProcess ) {
709737 return {
710738 result : ActionExecutionResultCode . Error ,
711- response : t ( 'CasparCGDevice: config.launcherProcess is not set!' ) ,
739+ code : CasparCGActionErrorCode . RESTART_LAUNCHER_PROCESS_NOT_SET ,
740+ context : { } ,
741+ response : t ( 'Cannot restart CasparCG: launcher process not configured' ) ,
712742 }
713743 }
714744
@@ -725,7 +755,9 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
725755 } else {
726756 return {
727757 result : ActionExecutionResultCode . Error ,
728- response : t ( 'Bad reply: [{{statusCode}}] {{body}}' , {
758+ code : CasparCGActionErrorCode . RESTART_BAD_REPLY ,
759+ context : { statusCode : response . statusCode , body : response . body } ,
760+ response : t ( 'CasparCG restart failed: launcher returned {{statusCode}} {{body}}' , {
729761 statusCode : response . statusCode ,
730762 body : response . body ,
731763 } ) ,
@@ -735,8 +767,10 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
735767 . catch ( ( error ) => {
736768 return {
737769 result : ActionExecutionResultCode . Error ,
738- response : t ( '{{message}}' , {
739- message : error . toString ( ) ,
770+ code : CasparCGActionErrorCode . RESTART_REQUEST_FAILED ,
771+ context : { errorMessage : error . toString ( ) } ,
772+ response : t ( 'CasparCG restart failed: {{errorMessage}}' , {
773+ errorMessage : error . toString ( ) ,
740774 } ) ,
741775 }
742776 } )
@@ -745,7 +779,9 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
745779 if ( ! this . _ccg ) {
746780 return {
747781 result : ActionExecutionResultCode . Error ,
748- response : t ( 'CasparCG device not initialized' ) ,
782+ code : CasparCGActionErrorCode . LIST_NOT_INITIALIZED ,
783+ context : { } ,
784+ response : t ( 'Cannot list CasparCG media: device not initialized' ) ,
749785 }
750786 }
751787 const result = await this . _ccg . executeCommand (
@@ -757,7 +793,9 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
757793 if ( result . error )
758794 return {
759795 result : ActionExecutionResultCode . Error ,
760- response : t ( `Error message from CasparCG: {{message}}` , { message : `${ result . error } ` } ) ,
796+ code : CasparCGActionErrorCode . LIST_CLS_ERROR ,
797+ context : { errorMessage : `${ result . error } ` } ,
798+ response : t ( `CasparCG media list failed: {{errorMessage}}` , { errorMessage : `${ result . error } ` } ) ,
761799 }
762800
763801 const request = await result . request
@@ -770,7 +808,11 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
770808 } else {
771809 return {
772810 result : ActionExecutionResultCode . Error ,
773- response : t ( `Error code {{code}} from CasparCG` , { code : request . responseCode } ) ,
811+ code : CasparCGActionErrorCode . LIST_BAD_RESPONSE ,
812+ context : { responseCode : request . responseCode } ,
813+ response : t ( `CasparCG media list failed: server returned error {{responseCode}}` , {
814+ responseCode : request . responseCode ,
815+ } ) ,
774816 }
775817 }
776818 }
0 commit comments