redstone_exception_mapper 0.0.1 copy "redstone_exception_mapper: ^0.0.1" to clipboard
redstone_exception_mapper: ^0.0.1 copied to clipboard

Dart 1 only

A plugin for Redstone.dart to map unhandled exceptions to shelf Responses.

example/redstone_exception_mapper.dart

// Copyright (c) 2015, <your name>. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

library redstone_exception_mapper.example;

import 'package:redstone/redstone.dart' as app;
import 'package:redstone_exception_mapper/redstone_exception_mapper.dart'
    as plugin;
import 'package:shelf/shelf.dart';

main() {
  app.addPlugin(plugin.ExceptionMapperPlugin);
  app.setupConsoleLog();
  app.showErrorPage = false;

  plugin.mappings = {
    NotFoundException: (NotFoundException e) => new Response.notFound(e.message)
  };

  app.start();
}

class NotFoundException implements Exception {
  final String message;

  const NotFoundException([this.message = ""]);

  String toString() => message;
}

@app.Group("/")
@plugin.ExceptionMapper()
class Users {
  @app.DefaultRoute()
  route_returning_ok() {
    return new Response.ok("");
  }

  @app.Route("mapped")
  route_returning_mapped_exception() {
    throw new NotFoundException('The requested page could not be found!');
  }

  @app.Route("unhandled")
  route_returning_unhandled_exception() {
    throw new Exception("Unhandled!");
  }
}
0
likes
30
points
2
downloads

Publisher

unverified uploader

Weekly Downloads

A plugin for Redstone.dart to map unhandled exceptions to shelf Responses.

License

BSD-3-Clause (license)

Dependencies

redstone, shelf

More

Packages that depend on redstone_exception_mapper