aboutsummaryrefslogtreecommitdiff
path: root/files/fr/web/javascript/reference/global_objects/aggregateerror/index.html
blob: 67d57db8ab3e6dfc27503e1ac67c710f07053d48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
title: AggregateError
slug: Web/JavaScript/Reference/Global_Objects/AggregateError
tags:
  - AggregateError
  - Classe
  - Experimental
  - Interface
  - JavaScript
translation_of: Web/JavaScript/Reference/Global_Objects/AggregateError
original_slug: Web/JavaScript/Reference/Objets_globaux/AggregateError
---
<div>{{JSRef}}</div>

<p>Un objet <code><strong>AggregateError</strong></code> représente une erreur lorsque plusieurs erreurs doivent être agrégées en une seule. Ce type d'exception est levée lorsque plusieurs erreurs sont rapportées par une opération, par exemple avec {{JSxRef("Promise.any()")}} lorsque l'ensemble des promesses qui lui sont passées échouent.</p>

<dl>
</dl>

<h2 id="Constructeur">Constructeur</h2>

<dl>
 <dt><a href="/fr/docs/Web/JavaScript/Reference/Objets_globaux/AggregateError/AggregateError"><code>AggregateError()</code></a></dt>
 <dd>Crée un nouvel objet <code>AggregateError</code>.</dd>
</dl>

<h2 id="Propriétés_des_instances">Propriétés des instances</h2>

<dl>
 <dt>{{JSxRef("Error.prototype.message", "AggregateError.prototype.message")}}</dt>
 <dd>Le message d'erreur. La valeur par défaut est <code>""</code>.</dd>
 <dt>{{JSxRef("Error.prototype.name", "AggregateError.prototype.name")}}</dt>
 <dd>Le nom de l'erreur. La valeur par défaut est <code>"AggregateError"</code>.</dd>
</dl>

<h2 id="Exemples">Exemples</h2>

<h3 id="Intercepter_une_erreur_AggregateError">Intercepter une erreur <code>AggregateError</code></h3>

<pre class="brush: js; notranslate">Promise.any([
  Promise.reject(new Error("une erreur")),
]).catch(e =&gt; {
  console.log(e instanceof AggregateError); // true
  console.log(e.message);                   // "All Promises rejected"
  console.log(e.name);                      // "AggregateError"
  console.log(e.errors);                    // [ Error: "une erreur" ]
});
</pre>

<h3 id="Créer_un_objet_AggregateError">Créer un objet <code>AggregateError</code></h3>

<pre class="brush: js; notranslate">try {
  throw new AggregateError([
    new Error("une erreur"),
  ], 'Coucou');
} catch (e) {
  console.log(e instanceof AggregateError); // true
  console.log(e.message);                   // "Coucou"
  console.log(e.name);                      // "AggregateError"
  console.log(e.errors);                    // [ Error: "une erreur" ]
}
</pre>

<h2 id="Spécifications">Spécifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Spécification</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('Promise.any', '#sec-aggregate-error-object-structure', 'AggregateError')}}</td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilité_des_navigateurs">Compatibilité des navigateurs</h2>

<div class="hidden">Le tableau de compatibilité de cette page a été généré à partir de données structurées. Si vous souhaitez contribuer à ces données, n'hésitez pas à consulter <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> et à nous envoyer une <em>pull request</em>.</div>

<p>{{Compat("javascript.builtins.AggregateError")}}</p>

<h2 id="Voir">Voir</h2>

<ul>
 <li>{{JSxRef("Error")}}</li>
</ul>