Created
October 29, 2019 19:17
-
-
Save zeryx/d2b9a5d548fe313e49513c87f9b49bd0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hidden or 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