Created
October 29, 2019 19:17
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.algorithmia.handler | |
import java.io.FileOutputStream | |
import java.io.PrintStream | |
import scala.util.Try | |
case class ResponseHandler(){ | |
val FIFOPATH = "/tmp/algoout" | |
private def write(data: String): Try[Unit] = { | |
Try(new PrintStream(new FileOutputStream(this.FIFOPATH, true))) | |
.map({s => s.println(data); s}) | |
.map({s => s.flush(); s}) | |
.map(_.close()) | |
} | |
def writeErrorToPipe(e: Throwable): Try[Unit] = { | |
val serializable = SerializableException.fromException(e) | |
write(serializable.serialize()) """no implicit definition of Writes[SerializableException]""" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.algorithmia.handler | |
import org.apache.commons.lang3.exception.ExceptionUtils | |
import play.api.libs.json._ | |
case class SerializableException(message: String, stacktrace: String, error_type: String) { | |
def serialize()(implicit s: Writes[SerializableException]): String = { | |
Json.toJson(this).toString() | |
} | |
} | |
object SerializableException { | |
def fromException(e: Throwable): SerializableException = { | |
val stackTrace = ExceptionUtils.getStackTrace(e) | |
val message = ExceptionUtils.getMessage(e) | |
val errorType = e.getClass.toString | |
SerializableException(message, stackTrace, errorType) | |
} | |
implicit def writes: (SerializableException => JsValue) => Writes[SerializableException] = Writes[SerializableException] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment