Problem
Your route needs to handle an error, stopping execution and returning an HTTP error code and message.
Solution
Create a new NetworkError object from errors (bottom of file). If you are in middleware or a synchronous function, throw it. If you are in an asynchronous function, call the callback with it.
Details
Joyent has a long document on proper error handling in Node, which is well worth reading. In particular: functions should either handle errors synchronously or asynchronously. Be aware that functions you call may throw an exception, and are not called in a co-express wrapped function, need to be handled manually (co-express catches errors and passes them to express' next function to be handled by error middleware).
Invalid input errors, such as not providing a property or parameter that is required, are returned with status code 422, Unprocessable Entity.
- Home
- Archmage Home
- Artisan Home
- Adventurer Home
- Scribe Home
- Diplomat Home
- Ambassador Home
- Archmage General
- Mission statement
- Coco Models
- Coding Guidelines
- Cookbook
- File system
- JSON Schema
- Technical overview
- Testing
- Third party software and services
- Artisan General
- Building A Level
- Coding Guidelines for Artisans
- Editing Thang Components
- Important Artisan Concepts
- Keyboard Shortcuts
- Artisan How-To Index
- Adventurer General
- Scribe General
- Diplomat General
- i18n
- i18n Glossary nb
- i18n Glossary ru
- i18n Glossary es-419
- Ambassador General
- Dev Setup
- Dev Setup: Linux
- Dev Setup: Windows
- Dev Setup: Mac
- Dev Setup: Vagrant
- Dev Setup: Issues
- Game Engine
- Component
- Multiplayer
- Surface
- System
- Thang
- Thang Component System
- Tome
- World
- Artisan Tabs
- Components And Systems
- Scripts
- Settings
- Thangs
- Other
- Aether
- Client models
- Developer organization
- Educational Standards
- Events, subscriptions, shortcuts
- Chat Room
- Chat Room Rules
- Permissions
- Project Ideas List
- Treema
- Versioning
- Views
CodeCombat | Home | Blog | Forum | Teachers | Legal | Contribute