diff --git a/h5p/classes/external.php b/h5p/classes/external.php index bf02172741a..837f6283928 100644 --- a/h5p/classes/external.php +++ b/h5p/classes/external.php @@ -99,9 +99,18 @@ class external extends external_api { $messages = $h5pplayer->get_messages(); } catch (\moodle_exception $e) { $messages = (object) [ - 'exception' => $e->getMessage(), 'code' => $e->getCode(), ]; + // To mantain the coherence between web coding error and Mobile coding errors. + // We need to return the same message error to Mobile. + // The 'out_al_local_url called on a non-local URL' error is provided by the \moodle_exception. + // We have to translate to h5pinvalidurl which is the same coding error showed in web. + if ($e->errorcode === 'codingerror' && + $e->a === 'out_as_local_url called on a non-local URL') { + $messages->exception = get_string('h5pinvalidurl', 'core_h5p'); + } else { + $messages->exception = $e->getMessage(); + } } if (empty($messages->error) && empty($messages->exception)) { diff --git a/h5p/tests/external_test.php b/h5p/tests/external_test.php index 70f613a56cd..9d02199a8d8 100644 --- a/h5p/tests/external_test.php +++ b/h5p/tests/external_test.php @@ -124,6 +124,17 @@ class core_h5p_external_testcase extends externallib_advanced_testcase { // Check the warnings to be sure that h5pinvalidurl is the message by moodle_exception. $this->assertEquals($urlempty, $result['warnings'][0]['item']); $this->assertEquals(get_string('h5pinvalidurl', 'core_h5p'), $result['warnings'][0]['message']); + + // Create a non-local URL. + $urlnonlocal = 'http://www.google.com/pluginfile.php/644/block_html/content/arithmetic-quiz-1-1.h5p'; + $result = external::get_trusted_h5p_file($urlnonlocal, 0, 0, 0, 0); + $result = external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result); + // Expected result: Just 1 record on warnings and none on files. + $this->assertCount(0, $result['files']); + $this->assertCount(1, $result['warnings']); + // Check the warnings to be sure that h5pinvalidurl is the message by moodle_exception. + $this->assertEquals($urlnonlocal, $result['warnings'][0]['item']); + $this->assertEquals(get_string('h5pinvalidurl', 'core_h5p'), $result['warnings'][0]['message']); } /**