@@ -773,19 +773,28 @@ Shell::GetServiceProtocolDescription() const {
773
773
}
774
774
775
775
static void ServiceProtocolParameterError (rapidjson::Document& response,
776
- std::string parameter_name ) {
776
+ std::string error_details ) {
777
777
auto & allocator = response.GetAllocator ();
778
778
response.SetObject ();
779
779
const int64_t kInvalidParams = -32602 ;
780
780
response.AddMember (" code" , kInvalidParams , allocator);
781
781
response.AddMember (" message" , " Invalid params" , allocator);
782
782
{
783
783
rapidjson::Value details (rapidjson::kObjectType );
784
- details.AddMember (" details" , parameter_name , allocator);
784
+ details.AddMember (" details" , error_details , allocator);
785
785
response.AddMember (" data" , details, allocator);
786
786
}
787
787
}
788
788
789
+ static void ServiceProtocolFailureError (rapidjson::Document& response,
790
+ std::string message) {
791
+ auto & allocator = response.GetAllocator ();
792
+ response.SetObject ();
793
+ const int64_t kJsonServerError = -32000 ;
794
+ response.AddMember (" code" , kJsonServerError , allocator);
795
+ response.AddMember (" message" , message, allocator);
796
+ }
797
+
789
798
// Service protocol handler
790
799
bool Shell::OnServiceProtocolScreenshot (
791
800
const blink::ServiceProtocol::Handler::ServiceProtocolMap& params,
@@ -803,8 +812,7 @@ bool Shell::OnServiceProtocolScreenshot(
803
812
response.AddMember (" screenshot" , image, allocator);
804
813
return true ;
805
814
}
806
- ServiceProtocolParameterError (response,
807
- " Could not capture image screenshot." );
815
+ ServiceProtocolFailureError (response, " Could not capture image screenshot." );
808
816
return false ;
809
817
}
810
818
@@ -825,7 +833,7 @@ bool Shell::OnServiceProtocolScreenshotSKP(
825
833
response.AddMember (" skp" , skp, allocator);
826
834
return true ;
827
835
}
828
- ServiceProtocolParameterError (response, " Could not capture SKP screenshot." );
836
+ ServiceProtocolFailureError (response, " Could not capture SKP screenshot." );
829
837
return false ;
830
838
}
831
839
@@ -897,7 +905,8 @@ bool Shell::OnServiceProtocolRunInView(
897
905
return true ;
898
906
} else {
899
907
FML_DLOG (ERROR) << " Could not run configuration in engine." ;
900
- response.AddMember (" type" , " Failure" , allocator);
908
+ ServiceProtocolFailureError (response,
909
+ " Could not run configuration in engine." );
901
910
return false ;
902
911
}
903
912
@@ -951,7 +960,7 @@ bool Shell::OnServiceProtocolSetAssetBundlePath(
951
960
return true ;
952
961
} else {
953
962
FML_DLOG (ERROR) << " Could not update asset directory." ;
954
- response. AddMember ( " type " , " Failure " , allocator );
963
+ ServiceProtocolFailureError (response , " Could not update asset directory. " );
955
964
return false ;
956
965
}
957
966
0 commit comments