{"record":{"id":"f57daf43e4486c8e","repo":"moodle/moodle","slug":"apierror","errorCode":null,"errorMessage":"apierror","messagePattern":"apierror","errorType":"exception","errorClass":"moodle_exception","httpStatus":null,"severity":"error","filePath":"public/blocks/tag_youtube/block_tag_youtube.php","lineNumber":347,"sourceCode":"\n            // Return an array with the relevant categories.\n            return array_reduce($categoryitems, function($categories, $category) use ($categorytranslations) {\n                $categoryid = $category['id'];\n                $categoryname = $category['snippet']['title'];\n                // Videos can be associated with this category.\n                if ($category['snippet']['assignable']) {\n                    // If the category name can be mapped with a translation, add it to the categories array.\n                    if (array_key_exists($categoryname, $categorytranslations)) {\n                        $categories[$categoryid] = $categorytranslations[$categoryname];\n                    } else { // Otherwise, display the untranslated category name and show a debugging message.\n                        $categories[$categoryid] = $categoryname;\n                        debugging(\"The category '{$categoryname}' does not have a translatable language string.\");\n                    }\n                }\n                return $categories;\n            }, []);\n        } else {\n            throw new \\moodle_exception('apierror', 'block_tag_youtube');\n        }\n    }\n\n    /**\n     * Method that provides mapping between the video category names and their translations.\n     *\n     * @return array The array that maps the video category names with their translations\n     */\n    private function category_map_translation() {\n        return [\n            'Film & Animation' => get_string('filmsanimation', 'block_tag_youtube'),\n            'Autos & Vehicles' => get_string('autosvehicles', 'block_tag_youtube'),\n            'Music' => get_string('music', 'block_tag_youtube'),\n            'Pets & Animals' => get_string('petsanimals', 'block_tag_youtube'),\n            'Sports' => get_string('sports', 'block_tag_youtube'),\n            'Travel & Events' => get_string('travel', 'block_tag_youtube'),\n            'Gaming' => get_string('gadgetsgames', 'block_tag_youtube'),\n            'People & Blogs' => get_string('peopleblogs', 'block_tag_youtube'),","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/moodle/moodle/blob/48ea8c33227277e916cdd4079dbecef448b37f2c/public/blocks/tag_youtube/block_tag_youtube.php#L329-L365","documentation":"Thrown by block_tag_youtube::get_categories() when the YouTube API response cannot be turned into a category mapping — i.e. the call to the YouTube video-category endpoint failed or returned no usable data. The block requires the category list to render its video widget, so it aborts with a block-specific 'apierror'.","triggerScenarios":"YouTube Data API request fails: invalid/expired API key, quota exceeded, network failure, YouTube blocking the region, or the response lacking the expected category items.","commonSituations":"YouTube API key missing or revoked; Google deprecated/enforced quota limits; server blocked from googleapis.com; plugin not updated after a YouTube API change (legacy API removed).","solutions":["Set/verify a valid YouTube Data API v3 key in the block settings (Admin > Plugins > Blocks > Tag YouTube).","Check the API quota in Google Cloud Console; wait for reset or raise the quota.","Confirm outbound HTTPS to www.googleapis.com works from the server.","Verify the plugin is a current version compatible with YouTube Data API v3.","Add caching or fallback rendering so a transient API failure does not break the page."],"exampleFix":"// before\n$cats = $this->get_categories(); // throws on any API hiccup\n// after\ntry {\n    $cats = $this->get_categories();\n} catch (\\moodle_exception $e) {\n    debugging($e->getMessage());\n    $cats = []; // render block without categories\n}","handlingStrategy":"try-catch","validationCode":"$apikey = get_config('block_tag_youtube', 'apikey'); if (empty($apikey)) { /* block cannot work */ }","typeGuard":null,"tryCatchPattern":"try {\n    $categories = $block->get_categories();\n} catch (\\moodle_exception $e) {\n    if ($e->errorcode === 'apierror') { debugging('YouTube API failure: ' . $e->getMessage()); $categories = []; }\n    else { throw $e; }\n}","preventionTips":["Keep a valid YouTube Data API v3 key configured","Monitor API quota usage in Google Cloud Console","Cache category lists to reduce API calls","Keep the plugin updated for API changes"],"tags":["moodle","youtube","api","network","external-service"],"backgroundTag":"upstream-api-error","analyzedSha":"48ea8c33227277e916cdd4079dbecef448b37f2c","analyzedAt":"2026-09-14T20:34:48.527Z","contentChangedAt":"2026-09-14T20:34:48.527Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}