Skip to content

Instantly share code, notes, and snippets.

@juancho088
Last active June 10, 2018 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juancho088/b3b03162f9d5cc6d881c6f4c273960a2 to your computer and use it in GitHub Desktop.
Save juancho088/b3b03162f9d5cc6d881c6f4c273960a2 to your computer and use it in GitHub Desktop.
Custom exceptions for a Kotlin Serverless project
package com.myblockbuster.core
/**
* Custom exception for our project
* @property code HTTP code that the client is going to receive
* @property message Exception message
* @constructor By default it will reply with a 500 HTTP method
*/
abstract class MyException(var code: Int, override var message: String): Exception(message) {
constructor() : this(500, "Internal MyBlockbuster Exception")
}
/**
* Exception thrown when the body doesn't contain all the required fields
* @property body Input body
*/
class InvalidArguments(private var body: String) :
MyException(400, "The entity $body doesn't contain all the required fields")
/**
* Router Exception (request-dispatcher)
* @property resource The route/resource that failed
* @constructor The default exception is 404 not found exception
*/
class RouterException(private var resource: String) :
MyException(404, "The route/resource $resource doesn't exist")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment