Error codes
A call of the kit reports its outcome in one of two ways and your view handles each of them in a different place:
- An error. The promise rejects with an
Errorwhose shortcodenames what stopped the call (the page is not in the webapp, the person refused or the webapp could not run it). - A result. The promise resolves with a string such as
'sent'or'not-allowed'that says how the call went once it ran.
try {
const result = await world.send(text); // a result: 'sent', 'failed' or 'not-allowed'
showResult(result);
} catch (error) {
showError(error.code); // an error: 'failed', 'too-big', ...
}Errors
| Code | From | In short |
|---|---|---|
'no-host' | connectToHost | The page is not inside the webapp or the webapp did not answer. |
'unsupported' | connectToHost | The webapp does not accept the version of your kit. |
'too-big' | send with a file | The file is over 20 MB. |
'declined' | askFor | The person refused. |
'unavailable' | askFor, identity, openProfile | The webapp cannot provide what was asked. |
'not-allowed-verb' | setPath, askFor, identity, openProfile, send with a file | The webapp is older than the kit. |
'failed' | every call the webapp runs | Something else went wrong. |
'no-host'
From: connectToHost(). Why: your page is not inside the UNaIVERSE webapp (it was opened on its own in a browser tab) or the webapp did not answer within timeoutMs (5 seconds by default).
What to do: show a short message with a link to the world in UNaIVERSE. While you build, use a fake world because it never gives this code.
'unsupported'
From: connectToHost(). Why: the webapp does not accept the version of the kit that your view uses.
What to do: use the kit from this site or from its GitHub repository (Installation). Both use version 1 of the webapp protocol. In the meantime the person sees the UNaIVERSE view of the world.
'too-big'
From: send({ file }). Why: the file is over 20 MB (20 * 1024 * 1024 bytes). The kit checks the size before reading the file and rejects without sending it or adding it to messages. A fake world gives this code too.
What to do: ask the person for a smaller file. To warn them before they press Send, compare the size of the file yourself:
if (file.size > 20 * 1024 * 1024) showError('Pick a file under 20 MB.');'declined'
From: askFor. Why: the person refused in the webapp now or in an earlier request made after the webapp loaded your view. A refusal lasts until the webapp loads your view again. Until then every new request rejects at once and shows the person no question.
What to do: do not ask again. Offer what works without the feature (for example a photo from a file instead of the camera).
'unavailable'
From: askFor, identity, openProfile. Why: the webapp cannot give what the call asked for in three cases: (1) it cannot grant browser features to your view, (2) it gives your view no me or (3) it cannot show a profile card here.
What to do: continue without that feature.
'not-allowed-verb'
From: setPath, askFor, identity, openProfile and send with a file. Why: the webapp is older than your kit and does not know this call. With send neither the file nor the text of the message is sent. onBack is the exception because it never fails. In such a webapp the back button keeps its usual behaviour.
What to do: continue without that call because the rest of your view still works. Hide the control that needs it (a file button, a profile card) and keep sending text and images as before.
'failed'
From: every call the webapp runs for your view (send, answer, retry, act, dataHistory, loadMore, setPath, askFor, identity, openProfile). Why: the webapp failed to run the call for a reason not covered by the other codes. This code is rare.
What to do: render the newest world and let the person try again. Treat any code missing from this page the same way.
The result 'failed' of send is a different thing. It is not an error and means the message was not delivered.
Results
send, answer, retry
All three resolve to a SendResult that says how the sending of a message ended.
| Result | What it means | What to do |
|---|---|---|
'sent' | Delivered. | Nothing. |
'failed' | Sent but not delivered. The message is in messages with status: 'failed'. (send also returns it when it gets an image together with a file or a file that cannot be read. In these cases nothing is sent and messages does not change.) | Offer its retry(). Send an image and a file as two messages. |
'not-allowed' | Nothing was sent. Either canSend is false, the value was empty or an agent could not be reached. answer also gives it for a question already answered or for values that name no field. retry gives it for a message that had not failed. | Disable your controls while canSend is false and render the newest world. |
act
| Result | What it means | What to do |
|---|---|---|
'requested' | The rules accepted the request. | Render its effect when it reaches the world. |
'refused' | The rules turned the request down or did not answer within 10 seconds. | Render the newest now.actions. |
'not-allowed' | The action is not in the current now.actions. | Render the newest now.actions. |
setPath
true when the webapp accepted the path and false when it ignored a path outside your site (setPath).
askFor
Because a refusal rejects with the error 'declined', askFor resolves only to true.
openProfile
true when the webapp shows the card. false for an id that belongs neither to the world nor to a member and for a member known only by its role (openProfile).
loadMore
The number of older messages added (0 when none are left).
States
Two status fields are neither errors nor results. Your view renders their values.
The status of a message
Only the messages of the person have it (GuiMessage.status). It is 'sending' while the message is pending and then becomes 'sent' or 'failed'.
The status of the world
world.status is 'online' while the person is in the world and 'ended' when the world has ended. For an agent it is 'connecting', 'online', 'offline', 'unreachable' or 'not-found'.
Testing your error handling
A fake world asks the person nothing and has no webapp that could fail. It gives none of the error codes of the webapp except 'too-big' for a file over 20 MB (the kit checks the size itself). Its failNext option makes the next message fail. To test how your view handles another code, call your handler with an error of that code:
handleError(Object.assign(new Error('test'), { code: 'failed' }));See also
- Errors and the person's controls: what the person controls and how a view handles errors.
- The recipes Explain a refused message and Test failures with a fake world.