@@ -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,27 @@ 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+ }
643650 }
644651 const response = await request
645652 if ( ! response ?. data [ 0 ] ) {
646- return { result : ActionExecutionResultCode . Error }
653+ return {
654+ result : ActionExecutionResultCode . Error ,
655+ code : CasparCGActionErrorCode . CLEAR_NO_CHANNELS ,
656+ context : { } ,
657+ }
647658 }
648659
649660 await Promise . all (
@@ -697,18 +708,35 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
697708 */
698709 private async restartCasparCG ( ) : Promise < ActionExecutionResult > {
699710 if ( ! this . initOptions ) {
700- return { result : ActionExecutionResultCode . Error , response : t ( 'CasparCGDevice._connectionOptions is not set!' ) }
711+ return {
712+ result : ActionExecutionResultCode . Error ,
713+ code : CasparCGActionErrorCode . RESTART_NOT_INITIALIZED ,
714+ context : { } ,
715+ response : t ( 'Cannot restart CasparCG: device not initialized' ) ,
716+ }
701717 }
702718 if ( ! this . initOptions . launcherHost ) {
703- return { result : ActionExecutionResultCode . Error , response : t ( 'CasparCGDevice: config.launcherHost is not set!' ) }
719+ return {
720+ result : ActionExecutionResultCode . Error ,
721+ code : CasparCGActionErrorCode . RESTART_LAUNCHER_HOST_NOT_SET ,
722+ context : { } ,
723+ response : t ( 'Cannot restart CasparCG: launcher host not configured' ) ,
724+ }
704725 }
705726 if ( ! this . initOptions . launcherPort ) {
706- return { result : ActionExecutionResultCode . Error , response : t ( 'CasparCGDevice: config.launcherPort is not set!' ) }
727+ return {
728+ result : ActionExecutionResultCode . Error ,
729+ code : CasparCGActionErrorCode . RESTART_LAUNCHER_PORT_NOT_SET ,
730+ context : { } ,
731+ response : t ( 'Cannot restart CasparCG: launcher port not configured' ) ,
732+ }
707733 }
708734 if ( ! this . initOptions . launcherProcess ) {
709735 return {
710736 result : ActionExecutionResultCode . Error ,
711- response : t ( 'CasparCGDevice: config.launcherProcess is not set!' ) ,
737+ code : CasparCGActionErrorCode . RESTART_LAUNCHER_PROCESS_NOT_SET ,
738+ context : { } ,
739+ response : t ( 'Cannot restart CasparCG: launcher process not configured' ) ,
712740 }
713741 }
714742
@@ -725,7 +753,9 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
725753 } else {
726754 return {
727755 result : ActionExecutionResultCode . Error ,
728- response : t ( 'Bad reply: [{{statusCode}}] {{body}}' , {
756+ code : CasparCGActionErrorCode . RESTART_BAD_REPLY ,
757+ context : { statusCode : response . statusCode , body : response . body } ,
758+ response : t ( 'CasparCG restart failed: launcher returned {{statusCode}} {{body}}' , {
729759 statusCode : response . statusCode ,
730760 body : response . body ,
731761 } ) ,
@@ -735,8 +765,10 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
735765 . catch ( ( error ) => {
736766 return {
737767 result : ActionExecutionResultCode . Error ,
738- response : t ( '{{message}}' , {
739- message : error . toString ( ) ,
768+ code : CasparCGActionErrorCode . RESTART_REQUEST_FAILED ,
769+ context : { errorMessage : error . toString ( ) } ,
770+ response : t ( 'CasparCG restart failed: {{errorMessage}}' , {
771+ errorMessage : error . toString ( ) ,
740772 } ) ,
741773 }
742774 } )
@@ -745,7 +777,9 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
745777 if ( ! this . _ccg ) {
746778 return {
747779 result : ActionExecutionResultCode . Error ,
748- response : t ( 'CasparCG device not initialized' ) ,
780+ code : CasparCGActionErrorCode . LIST_NOT_INITIALIZED ,
781+ context : { } ,
782+ response : t ( 'Cannot list CasparCG media: device not initialized' ) ,
749783 }
750784 }
751785 const result = await this . _ccg . executeCommand (
@@ -757,7 +791,9 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
757791 if ( result . error )
758792 return {
759793 result : ActionExecutionResultCode . Error ,
760- response : t ( `Error message from CasparCG: {{message}}` , { message : `${ result . error } ` } ) ,
794+ code : CasparCGActionErrorCode . LIST_CLS_ERROR ,
795+ context : { errorMessage : `${ result . error } ` } ,
796+ response : t ( `CasparCG media list failed: {{errorMessage}}` , { errorMessage : `${ result . error } ` } ) ,
761797 }
762798
763799 const request = await result . request
@@ -770,7 +806,11 @@ export class CasparCGDevice extends DeviceWithState<State, CasparCGDeviceTypes,
770806 } else {
771807 return {
772808 result : ActionExecutionResultCode . Error ,
773- response : t ( `Error code {{code}} from CasparCG` , { code : request . responseCode } ) ,
809+ code : CasparCGActionErrorCode . LIST_BAD_RESPONSE ,
810+ context : { responseCode : request . responseCode } ,
811+ response : t ( `CasparCG media list failed: server returned error {{responseCode}}` , {
812+ responseCode : request . responseCode ,
813+ } ) ,
774814 }
775815 }
776816 }
0 commit comments